-1

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

Naum
  • 125
  • 1
  • 3
  • 12

1 Answers1

0

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.

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
  • The passw and user is 100% valid. But there is a restriction that service can be called only from specific IP adress. – Naum Jun 27 '13 at 11:21
  • When I call service from my computer which IP is not allowed I get this error: ""Authentication of Username Password Token Failed", But, when I call service from computer with allowed IP adress I've got this error: "Could not find default endpoint element that references contract (serviceReference1.rzzzoService) in the ServiceModel Client configuration section. This maight be beacuse no configuration file was found for your application, or because no endpoint element matching contract could be found in the client element." – Naum Jun 27 '13 at 11:22
  • (1) Most probably, you will not get pas the IP filter without some serious hacking. The error about authentication problems simply informs you about that failure. However, it could be a bit more informative that just "auth failed".. Try asking the service admins to allow to connect from your second machine too - they should be able to do that. – quetzalcoatl Jun 27 '13 at 11:45
  • (2) The error clearly states the fault and possible cause: your EXE file cannot find the setup for **the service client library**. Ensure that you have copied the `myapp.exe.config` or `mylib.dll.config` file along with your application. If you have copied it and it lies with the .exe/dll file, then check if that .config file contains the client configuration: open in and look for `endpoint` elements. It should look similar to http://msdn.microsoft.com/en-us/library/ee535060(v=office.14).aspx If they are missing, regenerate your proxy from WSDL and check your solution's .config file again. – quetzalcoatl Jun 27 '13 at 11:48
  • Thank You very much, I don't copy myapp.exe.config... It works now. – Naum Jun 27 '13 at 12:07
  • I have only one question: Can I use this service with .net 2.0 app. I think 2.0 app can only use wcf services if it have basicHttpBinding. But I think this web service use custom binding, and not BasicHttpbinding. Am I right? – Naum Jun 28 '13 at 13:57
  • That should be a separate question ;) Indeed you'll have some problems, but essentially, I don't know. First, you might consider upgrading to 3.5, but since you say 2.0, then probably you dont want to. Then, consider this: .Net 3.5 with its WCF still uses CLR2.0. If you just add the DLLs ripped from .Net3.5/WCF to your app, you should be able to use 3.5-based service client in a 2.0 app without requiring the end user to install full 3.5. Check out the same exact question here: http://stackoverflow.com/questions/2178199/how-to-consume-wcf-wshttpbinding-service-in-application-built-in-2-0 – quetzalcoatl Jun 28 '13 at 14:13
  • Be sure to read all answers and check the external article that's provided there. Also, this may come handy, as a sample of custombinding: http://blog.allanglen.com/2010/05/implementing-a-minimal-soap-1-2-binding-in-wcf Sorry, but I cannot say/find/remember anything more. Net2.0 is quite .. stale. Try asking in that thread (http://stackoverflow.com/questions/2178199/how-to-consume-wcf-wshttpbinding-service-in-application-built-in-2-0), maybe those guys will remember something useful. – quetzalcoatl Jun 28 '13 at 14:16