在 WCF 中更改命名空间和 schemaLocation 属性 [英] Changing namespace and schemaLocation attributes in WCF

查看:31
本文介绍了在 WCF 中更改命名空间和 schemaLocation 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 C# 开发了一个 WCF 服务.我们的客户已经有一个用 Java 编写的客户端软件.他们说当他们尝试添加我们的 wcf 服务引用时,他们得到一个错误.他们认为是关于命名空间的问题.
我不太了解 WCF 中的命名空间或任何其他标记详细信息.
他们说 wcf 服务的 wsdl 输出必须如下所示:

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 reference, 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"/>

但我们的服务提供:

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

可以看出,我的服务没有像 id="base"namespace 这样的属性,schemaLocation 属性是不同的.
如何更改 WCF 以生成他们想要的 wsdl xml?

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?

推荐答案

如果您想从 tempuri.org(这是 WCF 默认的)更改服务的命名空间,您需要在 4 个地方进行更改:

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. 服务合同
  2. 数据合同
  3. 服务实施
  4. 端点配置元素中的BindingNamespace

例如:

// 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" />

然而,我真的不明白他们为什么告诉你这是必要的.作为服务的提供者,您提供什么命名空间取决于您而不是他们.无论此值设置为什么,它们在使用 wsdl 时都可能遇到相同的问题.

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.

schemaLocation 也是如此,同样,这个位置指向的位置并不取决于他们.当您在 xml 架构中进行导入时,架构定位实际上是完全可选的,因此如果它们依赖于其中的某些值,那么它们就不是 xsd 兼容的.

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.

我猜他们在使用您的 WSDL 时遇到了困难,并且不太明白出了什么问题,所以选择责怪您的服务.通过 basicHttpBinding 公开的服务元数据是整个 WCF 堆栈中最具互操作性的,并且应该 100% 可从 java 使用.

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?

这篇关于在 WCF 中更改命名空间和 schemaLocation 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆