WCF - Cannot obtain Metadata, but works when the XML Endpoint is removed?

前提是你 提交于 2019-12-23 16:59:56

问题


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

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'.

Here is my Web.Config: Link.

As you can see, I already have the

<serviceMetadata httpGetEnabled="true" /> 

as well as

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

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

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.

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

EDIT:

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.


回答1:


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

There is workaround to fix the issue:

  1. Change bindingConfiguration attribute for endpoint address="x" from web to web2
  2. Add new web2 webHttpBinding configuration (copy web configuration):

Code for new binding 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>

Update:

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.

Error in Trace Viewer:



来源:https://stackoverflow.com/questions/11627392/wcf-cannot-obtain-metadata-but-works-when-the-xml-endpoint-is-removed

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