WCF - 无法获取元数据,但在删除 XML 端点时有效? [英] WCF - Cannot obtain Metadata, but works when the XML Endpoint is removed?

查看:27
本文介绍了WCF - 无法获取元数据,但在删除 XML 端点时有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 WCF 测试客户端时遇到问题.我无法连接到我的 WebService,因为它不断出现此错误:

I'm having a problem with the WCF Test Client. I cannot connect to my WebService because it keeps hitting this error:

错误:无法从http://xxx.xxxxxxxx.xxx/DPITerminal.svc 如果这是 Windows(R) 您有权访问的通信基础服务,请检查您是否已在指定的位置启用元数据发布地址.有关启用元数据发布的帮助,请参阅MSDN 文档位于http://go.microsoft.com/fwlink/?LinkId=65455.WS-元数据交换错误 URI:http://xxx.xxxxxxxx.xxx/DPITerminal.svc
元数据包含无法解析的引用:'http://xxx.xxxxxxxx.xxx/DPITerminal.svc'.内容类型应用程序/肥皂+xml;服务不支持 charset=utf-8http://xxx.xxxxxxxx.xxx/DPITerminal.svc.客户和服务绑定可能不匹配.远程服务器返回了一个错误:(415)无法处理消息,因为内容类型'应用程序/soap+xml;charset=utf-8' 不是预期的类型'文本/xml;charset=utf-8'..HTTP GET 错误 URI:http://xxx.xxxxxxxx.xxx/DPITerminal.svc 出现错误正在下载http://xxx.xxxxxxxx.xxx/DPITerminal.svc".

Error: Cannot obtain Metadata from http://xxx.xxxxxxxx.xxx/DPITerminal.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://xxx.xxxxxxxx.xxx/DPITerminal.svc
Metadata contains a reference that cannot be resolved: 'http://xxx.xxxxxxxx.xxx/DPITerminal.svc'. Content Type application/soap+xml; charset=utf-8 was not supported by service http://xxx.xxxxxxxx.xxx/DPITerminal.svc. The client and service bindings may be mismatched. The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..HTTP GET Error URI: http://xxx.xxxxxxxx.xxx/DPITerminal.svc There was an error downloading 'http://xxx.xxxxxxxx.xxx/DPITerminal.svc'.

这是我的 Web.Config:链接.

Here is my Web.Config: Link.

如你所见,我已经有了

<serviceMetadata httpGetEnabled="true" /> 

以及

<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="mex" contract="IMetadataExchange" />

正如其他 StackOverflow 问题中所建议的那样.还是不行.

as suggested in the other StackOverflow questions. Still doesn't work.

我还注意到,当我评论以下端点时:

I also noticed that when I comment the following endpoint:

<endpoint address="x" behaviorConfiguration="poxBehavior" binding="webHttpBinding" bindingConfiguration="web" contract="xxx.xxxxxxxx.xxxxxx.WebService.IDPITerminal" />

一切都按预期进行.所以我猜我的 XML 端点有问题?这很奇怪,因为 XML Endpoint 共享 JSON Endpoint 的绑定配置,而 JSON 没有任何问题.

Everything works as expected. So I guess there's a problem with my XML Endpoint? It's weird since the XML Endpoint is sharing the JSON Endpoint's binding configuration, and the JSON one doesn't have any problems.

另外,让我澄清一下,我只遇到了 WCF 测试客户端的问题.JSON &XML 端点都正常工作.

Also, Let me clarify that I'm only having problems with the WCF Test Client. The JSON & the XML Endpoint is both working properly.

我尝试评论 XML 端点,发布,然后通过 WCF 测试客户端连接.然后我取消注释 XML Endpoint,重新发布.WCF 测试客户端仍然有效 - 我的意思是我可以发送和接收数据.当我刷新服务时,再次弹出无法获取元数据错误.

I tried to comment the XML Endpoint, publish, then connect via the WCF Test Client. Then I uncommented the XML Endpoint, republish. The WCF Test Client still works- I mean I can send and receive data. When I refreshed the service, the Cannot obtain Metadata error popped out again.

推荐答案

WCF 似乎不允许对 2 个端点使用相同的配置.

It seems that WCF does not allow to use the same configuration for 2 endpoints.

有解决方法可以解决此问题:

There is workaround to fix the issue:

  1. 将端点 address="x"bindingConfiguration 属性从 web 更改为 web2
  2. 添加新的 web2 webHttpBinding 配置(复制 web 配置):
  1. Change bindingConfiguration attribute for endpoint address="x" from web to web2
  2. Add new web2 webHttpBinding configuration (copy web configuration):

新绑定配置的代码:

<webHttpBinding>
    <binding name="web" ... />
    <binding name="web2" closeTimeout="00:10:00" openTimeout="00:10:00"
         sendTimeout="00:10:00" allowCookies="true" maxBufferSize="2147483647"
         maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
         <readerQuotas maxDepth="64" maxStringContentLength="2147483647"
            maxArrayLength="8192" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
    </binding>
</webHttpBinding>

更新:

WCF 测试客户端无法获取 webHttpBinding 的元数据,因为此类元数据不存在.RESTfull 服务不支持用于 basicHttpBindingwsHttpBinding 的 WSDL 或类似协议.当 WCF 测试客户端尝试在两种情况下(WCF 测试客户端失败时和未失败时)获取元数据时,服务返回错误,但出于某种原因,在建议的解决方法的情况下,WCF 测试客户端设法吞下错误.很难说为什么没有 WCF 测试客户端源代码.

WCF Test Client is not able to obtain metadata for webHttpBinding because such metadata does not exist. RESTfull service does not support WSDL or similar protocol that is used for basicHttpBinding or wsHttpBinding. Service returns error when WCF Test Client tries to get metadata in both cases (when WCF Test Client fails and when not) but for some reason in case of proposed workaround WCF Test Client manages to swallow error. It is hard to say why without WCF Test Client source codes.

跟踪查看器中的错误:

这篇关于WCF - 无法获取元数据,但在删除 XML 端点时有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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