【问题标题】:WCF service binding wsHttp vs. basic with no authenticationWCF 服务绑定 wsHttp 与没有身份验证的基本
【发布时间】:2010-09-29 11:35:09
【问题描述】:

我正在尝试使用匿名身份验证创建 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),要么收到“拒绝访问”消息(使用 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 的新手,所以我还没有把所有的鸭子排成一排。

谢谢,

【问题讨论】:

  • 你的客户端的配置是什么?

标签: wcf web-services anonymous basichttpbinding wshttpbinding


【解决方案1】:

错误表明您正在发送内容类型不受支持的 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>

【讨论】:

  • 感谢您的回复!我添加了您建议的配置并将端点地址设置为服务所在的 URL,现在我收到一个不同的错误。它以“无法打开安全通道,因为与远程端点的安全协商失败”开始。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-03
  • 1970-01-01
  • 1970-01-01
  • 2015-03-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多