Changing namespace and schemaLocation attribues in WCF

百般思念 提交于 2019-12-07 12:32:02

问题


I developed a WCF service in C#. Our customer already has a client software written in Java. They say when they try to add our wcf service referance, they get an error. They think that the problem about namespaces.
I don't know much about namespaces or any other tag details in WCF.
They say wcf service's wsdl output has to be like the following:

<xsd:import id="base" namespace="http://helios.theircompanyName.com/im schemaLocation="http://wwwdev1.theirCompanyName.com:8000/HeliosIM/im?xsd=1"/>

But our service gives:

<xsd:import schemaLocation="http://myComputerName/MyWcfProjectFolder/MyWcfService.svc?xsd=xsd0" namespace="http://tempuri.org/"/>

As it can be seen, my service has no attribute like id="base" and namespace, schemaLocation attributes are different.
How can I change WCF to generate wsdl xml like they want?


回答1:


If you want to change the namespace of your service from tempuri.org (which is the WCF default) you need to change it in 4 places:

  1. Service contract
  2. Data contracts
  3. Service implementation
  4. BindingNamespace in endpoint config element

For example:

// Service Contract
[ServiceContract(Namespace="http://myNamespace")]
public interface IMyService
{}

// Data Contract
[DataContract(Namespace="http://myNamespace")]
public class MyType
{}

// Service implementation
[ServiceBehavior(Namespace="http://myNamespace")]
public class Service : IMyService
{}

<!-- In config -->
<endpoint address="http://whatever" 
          bindingNamespace="http://myNamespace"
          binding="basicHttpBinding" 
          contract="Something.IMyService" />

HOWEVER, I don't really understand why they are telling you this is necessary. As the provider of the service, it's up to you rather than them what namespace you provide. Whatever this value is set to they will likely have the same problems consuming the wsdl.

The same goes with the schemaLocation, again, it's not up to them where this location points to. Schemalocation is actually completely optiona when you're doing an import in xml schema, so if they're dependent on some value being in there then they're not xsd compliant.

I would guess they're having difficulties consuming your WSDL and do not quite understand what is wrong, so have chosen to blame your service. The service metadata exposed over the basicHttpBinding is the most interoperable of the entire WCF stack, and should be 100% consumable from java.

How are they trying to build their client? Is your service running somewhere they can see it?



来源:https://stackoverflow.com/questions/19050696/changing-namespace-and-schemalocation-attribues-in-wcf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!