WCF服务绑定wsHttp与基本没有身份验证

时间:2010-09-29 11:35:10

标签: wcf web-services anonymous basichttpbinding wshttpbinding

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

  

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

现在我在我的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)或“Access is Denied”消息(使用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的新手,所以我还没有连续吃掉所有的鸭子。

谢谢,

1 个答案:

答案 0 :(得分:4)

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

在第二个示例中,问题是默认的WsHttpBinidng配置。默认情况下,WsHttpBinding使用邮件安全性和Windows身份验证=&gt;进行保护。异常,因为计算机位于不同的域中,因此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>