简体   繁体   中英

Calling a web soap webservice with basic authorization

I created a Project in visual studio and added a Service Reference to a wsdl-file. When I first tried to connect to my service I got an error message telling me that i need basic authorization.

So i followed question this question. And added the security tag to my app.config. However, now i get an error in my xml, that mode is not a valid attribute for securtiy and transport not a valid element.

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

any ideas what i am doing wrong?

Ok, the problem was that i could not add the security tag to my custombinding, which was created automatically when I added the refernece. So I deleted the <customBinding><...></custombinding> and added a <basciHttpBinding> as described here . Afterwards I had to change the <endpoint> , to point to the new binding.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM