【问题标题】:Calling a web soap webservice with basic authorization使用基本授权调用 web 肥皂 web 服务
【发布时间】:2018-02-20 18:33:33
【问题描述】:

我在 Visual Studio 中创建了一个项目,并向 wsdl 文件添加了一个服务引用。当我第一次尝试连接到我的服务时,我收到一条错误消息,告诉我我需要基本授权。

所以我关注了问题this 问题。并将安全标签添加到我的 app.config 中。但是,现在我的 xml 中出现错误,该模式不是安全的有效属性,并且传输不是有效的元素。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="ConfigurationPortBinding">
          <mtomMessageEncoding messageVersion="Soap11" />
            <httpTransport />
            <security mode="TransportCredentialOnly">
              <transport clientCredentialType="Basic" />
            </security>
        </binding>
     </customBinding>
   </bindings>
   <client>
     <endpoint address="http://xxxx/CoreServices/ConfigurationService"
            binding="customBinding" bindingConfiguration="ConfigurationPortBinding"
            contract="ServiceReference1.Configuration" name="ConfigurationPort" />
   </client>
   </system.serviceModel>
</configuration>

任何想法我做错了什么?

【问题讨论】:

  • 请通过以下答案:*.com/a/3496268/4222487
  • 这就是我将安全标签添加到我的 ConfigurationPortBinding 的原因。但是,我收到一条错误消息,告诉我 app.config 中的标签“security”没有属性“mode”

标签: c# web-services soap webservices-client


【解决方案1】:

好的,问题是我无法将安全标签添加到我的自定义绑定中,它是在我添加引用时自动创建的。所以我删除了&lt;customBinding&gt;&lt;...&gt;&lt;/custombinding&gt; 并添加了&lt;basciHttpBinding&gt;,如here 所述。之后我不得不更改&lt;endpoint&gt;,以指向新的绑定。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup><.../></startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicAuthConf">
                    <security mode="TransportCredentialOnly">
                        <transport clientCredentialType="Basic" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://xxxx/CoreServices/ConfigurationService"
                binding="basicHttpBinding" bindingConfiguration="BasicAuthConf"
                contract="ServiceReference1.Configuration" name="ConfigurationPort" />
        </client>
    </system.serviceModel>
</configuration>

【讨论】: