错误:无法获取元数据

时间:2014-10-07 11:33:37

标签: c# web-services wcf wcf-binding

当我将服务部署到测试服务器时,当我尝试通过wcf测试客户端使用它时,我收到以下错误(尽管它在localhost下工作):

Error: Cannot obtain Metadata from http://internal/RegisterService/RegisterService.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  
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 

我的web.config看起来像这样:

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
                <etwTracking profileName="EndToEndMonitoring Tracking Profile"/>
            </behavior>
            <behavior name="wsSecureBehavior">
                <serviceMetadata httpsGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false"/>
    <protocolMapping>
        <add scheme="http" binding="basicHttpBinding"/>
        <add scheme="https" binding="wsHttpBinding"/>
    </protocolMapping>
    <diagnostics etwProviderId="830b12d1-bb5b-4887-aa3f-ab508fd4c8ba">
        <endToEndTracing propagateActivity="true" messageFlowTracing="true"/>
    </diagnostics>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IWcfService" closeTimeout="00:11:00" openTimeout="00:11:00" receiveTimeout="00:10:00" sendTimeout="00:11:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                    <message clientCredentialType="UserName" algorithmSuite="Default"/>
                </security>
            </binding>
        </basicHttpBinding>
        <wsHttpBinding>
            <binding name="wsHttp_IWcfService" maxBufferPoolSize ="2147483647" maxReceivedMessageSize="2147483647">
                <security mode="Transport">
                    <transport clientCredentialType="None"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service name="Services.WCF.RegisterService" behaviorConfiguration="wsSecureBehavior" >
            <endpoint address="secure" binding="wsHttpBinding" bindingConfiguration="wsHttp_IWcfService" name="registerServiceSecure" contract="Services.WCF.IRegisterService"/>
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWcfService" name="RegisterService" contract="Services.WCF.IRegisterService"/>
            <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
        </service>
    </services>
</system.serviceModel>

接口:

namespace Services.WCF
{
    [ServiceContract]
    public interface IRegisterService
    {
       ...
    }
}

服务

namespace Services.WCF
{
    public class RegisterService : IRegisterService
    {
        ....
    }       
}

我查看过很多帖子但是找不到相同的错误但找不到解决方法。我尝试过以下方法:

  • 确保服务名称在web.config和svc文件中匹配
  • 删除mex绑定
  • 添加基本主机
  • 确保windows / temp文件夹具有iis权限

我可以浏览到网址,它看起来不错,但我无法通过测试客户端访问它,并想知道我可能还缺少什么

1 个答案:

答案 0 :(得分:0)

在浏览了很多关于此主题的帖子后,我发现了这篇文章:Error: Cannot obtain Metadata from http ......?wsdl并尝试了包含远程服务器自签名证书的选项,这似乎解决了这个问题为了我。删除https的绑定也有效