2

我正在尝试使用匿名身份验证创建 WCF 服务。当我将服务部署到不在我当前域上的目标服务器时,我在尝试调用它时收到以下错误:

内容类型应用程序/soap+xml;服务http://myserver.com/page.svc不支持 charset=utf-8 。客户端和服务绑定可能不匹配。

就目前而言,我的 web.config 文件中有以下部分用于服务:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
    </modules>
  </system.webServer>

我一直在尝试各种绑定(wsHttpBinding 和 basicHttpBinding),但要么收到上述错误(使用 basicHttpBinding),要么收到“拒绝访问”消息(使用 wsHttpBinding)。这是我在使用 wsHttpBinding 时尝试使用的 web.config 部分

 <system.serviceModel>
  <services>
   <service behaviorConfiguration="AMP.MainBehavior" name="AMP.Main">
    <endpoint address="" binding="wsHttpBinding" contract="AMP.IMain">
      <identity>
        <dns value="myservice.com"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
   </service>
  </services>
  <behaviors>
    <serviceBehaviors>
    <behavior name="AMP.MainBehavior">
     <serviceMetadata httpGetEnabled="true"/>
     <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
   </serviceBehaviors>
  </behaviors>
 </system.serviceModel>

该服务是使用 .NET 4.0 框架创建的。我需要它是匿名的,但我不确定我错过了什么。我是 WCF 的新手,所以我还没有把所有的鸭子排成一排。

谢谢,

4

1 回答 1

3

该错误表明您正在发送内容类型不受支持的 HTTP 请求。SOAP 1.2 中使用了提到的内容类型,但 BasicHttpBinding 使用具有不同内容类型(text/xml;charset=utf-8)的 SOAP 1.1。因此,您的服务和客户端配置之间可能存在一些不匹配。

在您的第二个示例中,问题是默认的 WsHttpBinidng 配置。WsHttpBinding 默认使用消息安全性和 Windows 身份验证 => 异常进行保护,因为机器位于不同的域中,因此 Windows 身份验证无法工作。您必须定义自己的 WsHttpBinding 配置。试试这个(客户端必须使用相同的绑定配置):

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="Unsecured">
        <security mode="None" />   
      </binding>
    </wsHttpBinding>
  </bindings>
  <services>
    <service ...>
      <endpoint address="..." contract="..." 
         binding="wsHttpBinding" bindingConfiguration="Unsecured" />
      ...
    </service>
  </services>
</system.serviceModel>
于 2010-09-29T11:51:51.593 回答