我在visual studio中创建了一个Project,并在wsdl文件中添加了一个Service Reference。当我第一次尝试连接到我的服务时,我收到一条错误消息,告诉我需要基本授权。
所以我跟着问题this提问。并将安全标记添加到我的app.config中。但是,现在我的xml中出现错误,该模式不是securtiy的有效属性,也不是传输有效元素。
<?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>
任何想法我做错了什么?
答案 0 :(得分:0)
好的,问题是我无法将安全标记添加到我的自定义绑定中,这是在我添加引用时自动创建的。我删除了<customBinding><...></custombinding>
并添加了<basciHttpBinding>
,如here所述。之后我不得不改变<endpoint>
,指向新的绑定。
<?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>