使用wshttpbinding在internet上消费WCF服务

本文关键字:WCF 服务 wshttpbinding internet 使用 | 更新日期: 2023-09-27 17:53:35

我基本上遵循了这个教程

让所有东西在我的本地机器上正常运行。我已经把它部署在IIS中,并允许必要的防火墙端口,所以我去我的客户端PC驻留在一个不同的域。

我在这台机器上启动了WCF测试客户端,输入WSDL的URL,就可以查看服务调用了。唯一的事情是,当我实际尝试使用该方法并发送我的值时,我得到以下响应

"调用者未被服务认证"

奇怪-即使它仍然在本地工作,它不会在另一台机器上工作。是否有一种特定的方式来配置客户端基于我在做什么?

这是我的web.config

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WCF33.Service1">
        <endpoint address ="" binding="wsHttpBinding" contract="WCF33.IService1" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/WCF33/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

我遵循的教程在消息头中传递一个密钥并基于该密钥进行身份验证,但这不是问题所在。我认为这与http绑定有关,但我确实需要这种类型的加密。

有没有人能给我一些关于如何解决这个问题的信息/建议:)

使用wshttpbinding在internet上消费WCF服务

我遵循的教程在消息头中传递一个密钥并基于该密钥进行身份验证,但这不是问题。

你在通话中传递了密钥吗?如果你正在运行的代码期望在身份验证头中有一些东西,而它不在那里,可能会导致错误返回

好了,我现在已经排序了,我有两个主要问题,这个问题实际上最终成为我的第一个障碍。

使用wshttpbinding,我必须以编程方式配置客户端,创建wshttpbinding并将其附加到服务的实例。我还必须通过windows证书。一旦我这样做,呼叫者被认证的消息消失。

错误的下一个阶段是应用程序/xml错误,其中预期的响应与soap 1.2格式不匹配。这是一个奇怪的问题,因为由于某些原因,即使绑定服务器端是http,它在部署时默认为basichttp。为了解决这个问题,在wcf配置编辑器中有一个映射部分,您可以将协议映射到绑定。在这里,http被设置为basichttp,只需将其更改为wshttp,就可以了:)

希望这对某些人有所帮助,因为这两个错误似乎无处不在,根本没有答案!!