首页 新闻 赞助 找找看

C# 调用Java webservices 需要用户密码的方式

0
悬赏园豆:100 [待解决问题]

1 在Vs 中添加 web services 方式 的代码,是可以成功的,如下

  DE_UnfreezeSOAPSoapBindingQSService client = new DE_UnfreezeSOAPSoapBindingQSService();

            var key = Guid.NewGuid().ToString();


            client.Credentials = new NetworkCredential("username", "pwd");

2 在VS中添加服务引用的方式

方式1

 DE_UnfreezeClient client = new DE_UnfreezeClient();
 client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "pwd";

方式  2

DE_UnfreezeClient client = new DE_UnfreezeClient();
client.ClientCredentials.HttpDigest.ClientCredential = new NetworkCredential("username", "pwd"); ;

 

 

报错信息如下。 应该如何传递用户账号信息呢?

 

“System.ServiceModel.Security.MessageSecurityException”类型的未经处理的异常在 mscorlib.dll 中发生 

其他信息: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm="weblogic"'.
HelloHongfu的主页 HelloHongfu | 初学一级 | 园豆:47
提问于:2016-03-03 17:51
< >
分享
所有回答(2)
0

https://msdn.microsoft.com/en-us/library/ms789011.aspx

jello chen | 园豆:7306 (大侠五级) | 2016-03-03 22:44
0

需要设置代码

  
                        BasicHttpBinding binding;
                        Uri address = new Uri(serviceUrl);
                      

                        binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
                        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;


                        binding.CloseTimeout = new TimeSpan(3, 0, 0);
                        binding.OpenTimeout = new TimeSpan(3, 0, 0);
                        binding.ReceiveTimeout = new TimeSpan(3, 0, 0);
                        binding.SendTimeout = new TimeSpan(3, 0, 0);
                        binding.MaxReceivedMessageSize = 65536000;

                        EndpointAddress addr = new EndpointAddress(serviceUrl);

                        _serviceFactory = new ChannelFactory<DE_Unfreeze>(binding, addr);
                        _serviceFactory.Credentials.UserName.UserName = userName;
                        _serviceFactory.Credentials.UserName.Password = pwd;

 

HelloHongfu | 园豆:47 (初学一级) | 2016-07-21 16:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册