Web Reference works, but A Service Reference complains about Soap version

风格不统一 提交于 2019-12-12 00:08:37

问题


I have to connect to a legacy web service.

In visual studio, if I do a Add Service Reference, then enter the url of the WSDL file on server. My service shows up, and I write the code against it. But when I run the code I get this error:

System.ServiceModel.CommunicationException: The envelope version of the incoming message (Soap12 (http://www.w3.org/2003/05/soap-envelope)) does not match that of the encoder (Soap11 (http://schemas.xmlsoap.org/soap/envelope/)). Make sure the binding is configured with the same version as the expected messages.

My app.config looks like this:

  <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="LoginServiceSoap" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://server/Service.asmx" binding="basicHttpBinding"
                bindingConfiguration="LoginServiceSoap" contract="Stuff.Login.LoginServiceSoap"
                name="LoginServiceSoap" />
        </client>
    </system.serviceModel>

However, I am able to communicate with the service fine, if I add a 'Web Reference'. But my understanding is that I am supposed to use Service References now, instead of WebReferences. I am assuming I have something wrong in my above config.

Or am I forced to use a Web Reference, because of the type of service I am connecting to?


回答1:


Sheamus,

You could (theoretically) add the version number to the binding definition.

envelopeVersion="None/Soap11/Soap12"

With, of course, the right value for your service.

So it would look more like:

<basicHttpBinding>
    <binding name="LoginServiceSoap"
             envelopeVersion="Soap12" />
</basicHttpBinding>

Hope this helps you do things your way.



来源:https://stackoverflow.com/questions/15396885/web-reference-works-but-a-service-reference-complains-about-soap-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!