如何连接到网络服务? [英] How to connect to the web service?

查看:34
本文介绍了如何连接到网络服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接到这个地址上的网络服务:https://webapp2.rzzo.rs/rzzo/RzzoService?wsdl我在我的 .net 4.0 C# 应用程序中添加了对它的服务引用.这是我用来连接到这个服务的代码:

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

推荐答案

好吧,您首先要检查 WSDL 和/或服务文档,以找出需要什么身份验证..

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

WSDL 建议WSS11"sp:SignedEncryptedSupportingTokens",幸运的是证书要求似乎已关闭.

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

MSDN 知道这个方案:http://msdn.microsoft.com/en-us/library/aa738565.aspx
第 3.1.1 节 UsernameOverTransport,所以应该支持.

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.

您是否 100% 确定用户名和密码有效并且此帐户未被禁用?既然你得到了合理的回应,我敢打赌这就是问题所在..

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

如果它抱怨某些配置或绑定不匹配,请检查您的 serviceclient 配置(可能位于 yourapp.config 中)并确保它在 binding 标记中写入了正确的安全类型,例如.但它没有抱怨..

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

您是否 100% 确定用户名和密码有效并且此帐户未被禁用?既然您得到了合理的回应,我敢打赌这就是问题所在.我只是惊讶地看到错误消息中的令牌"一词.也许有一些身份验证令牌要从服务器接收,并且必须在每次身份验证尝试时传回,例如 http cookie?尝试检查服务的文档.

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.

这篇关于如何连接到网络服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆