代码之家  ›  专栏  ›  技术社区  ›  Scott Vercuski

WCF服务绑定wsHttp与无身份验证的basic

  •  2
  • Scott Vercuski  · 技术社区  · 14 年前

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

    内容类型应用/soap+xml; http://myserver.com/page.svc . 客户端和服务绑定可能是 不匹配。

      <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)。这是你的名字web.config文件我在使用wsHttpBinding时尝试使用的部分

     <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>
    

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

    谢谢您,

    1 回复  |  直到 14 年前
        1
  •  3
  •   Ladislav Mrnka    14 年前

    错误说明您正在发送内容类型为不受支持的HTTP请求。上面提到的内容类型在soap1.2中使用,但是BasicHttpBinding将soap1.1与不同的内容类型(text/xml;charset=utf-8)一起使用。因此,您的服务和客户机配置之间可能存在一些不匹配。

    <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>
    
    推荐文章