How to connect to the web service?

时光毁灭记忆、已成空白 提交于 2019-12-25 18:45:09

问题


I want to connect to web service which is on this adress: https://webapp2.rzzo.rs/rzzo/RzzoService?wsdl I add service reference to it in my .net 4.0 C# app. And here is my code which I used to connect to this servis:

 ServiceReference1.RzzoServiceClient client = new ServiceReference1.RzzoServiceClient();
            client.ClientCredentials.UserName.UserName = "------";
            client.ClientCredentials.UserName.Password = "-------";
            bool check = client.CheckConnection();

and here is message i must get (I got it from my service provider):

 <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-
utility-1.0.xsd">
    <s:Header>
        <o:Security s:mustUnderstand="1"
xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-
secext-1.0.xsd">
            <o:UsernameToken u:Id="uuid-cdf8690a-e56a-4efa-923c-760d22b6748d-7">
                <o:Username>username</o:Username>
                <o:Password>password</o:Password>
            </o:UsernameToken>
        </o:Security>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <GetInsuranceDataF xmlns="http://service.rzzo.rs/">
            <req xmlns="">
                <lbo/>
                <zk>11111111111</zk>
            </req>
        </GetInsuranceDataF>
    </s:Body>
</s:Envelope>

But I'm unable to connect to service. Please help


回答1:


Well, you'd start with checking the WSDL and/or the service docs to find out what authentication is required..

The WSDL suggests "WSS11" "sp:SignedEncryptedSupportingTokens", fortunatelly certificate requirement seems to be turned off.

MSDN knows this scheme: http://msdn.microsoft.com/en-us/library/aa738565.aspx
section 3.1.1 UsernameOverTransport, so that should be supported.

Setting the username and password should be as easy as:

var svc = new SomethingServiceClient(); // your proxy class generated from WSDL
svc.ClientCredentials.UserName.UserName = "someUsername";
svc.ClientCredentials.UserName.Password = "somePassword";

And this is exactly what you say you are trying, so that's weird.

Are you 100% sure that the username and password are valid and that this account is not disabled? Since you are getting a reasonable response, I'd bet that this is the problem..

If it were complaining about some configuration or binding mismatch, check your serviceclient configuration (probably will sit in yourapp.config) and ensure that it has proper security type written inside the binding tag, for example <security authenticationMode="UserNameOverTransport" />. But its not complaining..

Are you 100% sure that the username and password are valid and that this account is not disabled? Since you are getting a reasonable response, I'd bet that this is the problem.. I'm only suprised to see the word "Token" in the error message. Maybe there's some authentication token to be received from the server and that must be passed back at every authentication attempt, like a http cookie? Try checking the service's docs.



来源:https://stackoverflow.com/questions/17323898/how-to-connect-to-the-web-service

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