且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用WCF over HTTP连接到受密码保护的服务器

更新时间:2022-03-16 17:24:21

如果您不知道怎么做,您应该问服务提供商如何获得服务?找到它。

You should ask service provider how is service secured if you don't know how to find it.

您的网站似乎正在使用基本的HTTP身份验证。对于此类身份验证,您需要创建自定义 webHttpBinding 配置:

It looks like your site is using basic HTTP authentication. For such authentication you need to create custom webHttpBinding configuration:

<system.serviceModel>
  <client>
    <endpoint address="http://MyUrl/"
              binding="webHttpBinding"
              bindingConfiguration="secured"
              behaviorConfiguration="MyData"
              contract="MyNameSpace.MyIService"
              name="MyData"/>
  </client>
  <bindings>
    <webHttpBinding>
      <binding name="secured">
        <security mode="TransportCredentialOnly">
          <transport clientCredentialType="Basic" />
        </security>
      </binding>
    </webHttpBinding>
  </bindings>
  <behaviors>
    <endpointBehaviors>
      <behavior name="MyData">
        <webHttp/>
      </behavior>
    </endpointBehaviors>
  </behaviors>
</system.serviceModel>