WCF - Cannot obtain Metadata, but works when the XML Endpoint is removed?
我在使用 WCF 测试客户端时遇到问题。我无法连接到我的 WebService,因为它一直出现此错误:
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:链接。
如你所见,我已经有了
1 | <serviceMetadata httpGetEnabled="true" /> |
以及
1 | <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="mex" contract="IMetadataExchange" /> |
正如其他 StackOverflow 问题中所建议的那样。还是不行。
我还注意到,当我评论以下端点时:
1 | <endpoint address="x" behaviorConfiguration="poxBehavior" binding="webHttpBinding" bindingConfiguration="web" contract="xxx.xxxxxxxx.xxxxxx.WebService.IDPITerminal" /> |
一切都按预期进行。所以我猜我的 XML Endpoint 有问题?这很奇怪,因为 XML Endpoint 共享 JSON Endpoint 的绑定配置,而 JSON 没有任何问题。
另外,让我澄清一下,我只是在使用 WCF 测试客户端时遇到问题。 JSON
WCF 似乎不允许对 2 个端点使用相同的配置。
有解决此问题的解决方法:
新绑定配置代码:
1 2 3 4 5 6 7 8 9 | <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 测试客户端无法获取
跟踪查看器中的错误: