元数据包含无法解析的引用。

时间:2014-02-05 07:46:48

标签: c# wcf web-services

以下是我的WCF配置。我在IIS中发布它并尝试从Windows窗体客户端连接到它。

<system.serviceModel>
<client />
<bindings>
  <wsHttpBinding>
    <binding name="BindingConfiguration">
      <security>
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </wsHttpBinding>      
</bindings>
<services>
  <service name="Service" behaviorConfiguration="BehaviorConfiguration">        
    <endpoint address="" binding="wsHttpBinding" name="wsBinding" contract="WCFHttps.IService1" bindingConfiguration="BindingConfiguration"/>
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name= "BehaviorConfiguration">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <serviceCredentials>            
        <userNameAuthentication userNamePasswordValidationMode="Windows"/>
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->

尝试在测试客户端中添加服务引用时会抛出错误。

    The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: '****/Service1.svc?wsdl'.
Content Type application/soap+xml; charset=utf-8 was not supported by service ****/Service1.svc?wsdl.  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'..
If the service is defined in the current solution, try building the solution and adding the service reference again.

我还通过C:\ Windows \ Temp文件夹授予了IIS_USRS的读/写权限,但问题仍然存在。任何人都可以在这里提出错误的建议。

感谢。

2 个答案:

答案 0 :(得分:0)

<强>原因: 当您尝试引用WCF服务IIS尝试访问C:\ Windows \ Temp文件夹时,此错误的原因很简单。如果ASP.NET或IIS_IUSER(基于Windows版本)帐户无权访问此文件夹,您将看到此错误。

<强>解决方案: 将ASP.NET或IIS_USER帐户添加到此文件夹,或者为您运行应用程序的用户帐户授予管理员权限。

配置跟踪 http://msdn.microsoft.com/en-us/library/ms733025.aspx

答案 1 :(得分:0)

在我的情况下,在web.config文件中指定了错误的命名空间。它必须与.svc文件的命名空间相同:

 <service name="NAMESPACE.SvcFileName">
    <endpoint contract="NAMESPACE.IContractName" />
  </service>

示例:

<service name="MyNameSpace.FileService">
<endpoint contract="MyNameSpace.IFileService" />
</service>

(这些样本中省略了不相关的标签)