Winforms 使用.net 4 WCF中的ws-security java服务
我试图使用Soap头中带有基本用户名/密码令牌的JAX-WSWeb服务。我已经测试过JAX-WS服务是否与SoapUI一起工作。现在我转到.net客户端。.net客户端将是一个windows窗体应用程序。我已经添加了服务引用并设置了用户名和密码值。当我执行web方法时,soap xml中没有安全头。根据我在研究中收集的信息,我需要将服务客户端设置为使用消息级安全性。这就是我被困的地方,我想不出来 这是我的密码Winforms 使用.net 4 WCF中的ws-security java服务,winforms,wcf,.net-4.0,jax-ws,Winforms,Wcf,.net 4.0,Jax Ws,我试图使用Soap头中带有基本用户名/密码令牌的JAX-WSWeb服务。我已经测试过JAX-WS服务是否与SoapUI一起工作。现在我转到.net客户端。.net客户端将是一个windows窗体应用程序。我已经添加了服务引用并设置了用户名和密码值。当我执行web方法时,soap xml中没有安全头。根据我在研究中收集的信息,我需要将服务客户端设置为使用消息级安全性。这就是我被困的地方,我想不出来 这是我的密码 MyServiceProxy serverService = new MyServic
MyServiceProxy serverService = new MyServiceProxy.MyServiceProxyClient();
MyServiceProxy inputVO = new MyServiceProxy.getAddressFormatInput();
MyServiceProxy outputVO = new MyServiceProxy.getAddressFormatOutput();
//set username and passwrd
serverService.ClientCredentials.UserName.UserName = "username";
serverService.ClientCredentials.UserName.Password = "PASSWORD";
inputVO.addressNumber = 13602;
inputVO.addressNumberSpecified = true;
outputVO = serverService.GetAddressFormat(inputVO);
它正在发布这个
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:orac="http://oracle.e1.bssv.JP550010/">
<soapenv:Body>
<orac:GetAddressFormat>
<addressNumber>13602</addressNumber>
</orac:GetAddressFormat>
</soapenv:Body>
安全设置在绑定上,绑定通常在XML配置文件中设置。看
要从代码进行设置,请使用myServiceProxCyclientBinding EndpointAddress构造函数。我认为您需要指定一个安全设置-basicHttpBinding的默认设置为None。修改配置文件的以下部分:
<bindings>
<basicHttpBinding>
<binding name="MyWebServiceProxyPortBinding">
<security mode="Message" clientCredentialType="UserName" />
</binding>
</basicHttpBinding>
</bindings>
使用此链接解决问题
在代码中,我做了以下操作
var securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityElement.AllowInsecureTransport = true;
securityElement.EnableUnsecuredResponse = true;
var encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
var transportElement = new HttpTransportBindingElement();
var binding = new CustomBinding(securityElement, encodingElement, transportElement);
ServiceReference1.MyWebServiceProxyClient client = new ServiceReference1.MyWebServiceProxyClient();
ServiceReference1.getAddressFormatInput inputVO = new ServiceReference1.getAddressFormatInput();
ServiceReference1.getAddressFormatOutput outputVO = new ServiceReference1.getAddressFormatOutput();
client.Endpoint.Binding = binding;
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";
inputVO.addressNumber = 13602;
inputVO.addressNumberSpecified = true;
outputVO = client.GetAddressFormat(inputVO);
var securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityElement.AllowInsecureTransport = true;
securityElement.EnableUnsecuredResponse = true;
var encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
var transportElement = new HttpTransportBindingElement();
var binding = new CustomBinding(securityElement, encodingElement, transportElement);
ServiceReference1.MyWebServiceProxyClient client = new ServiceReference1.MyWebServiceProxyClient();
ServiceReference1.getAddressFormatInput inputVO = new ServiceReference1.getAddressFormatInput();
ServiceReference1.getAddressFormatOutput outputVO = new ServiceReference1.getAddressFormatOutput();
client.Endpoint.Binding = binding;
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";
inputVO.addressNumber = 13602;
inputVO.addressNumberSpecified = true;
outputVO = client.GetAddressFormat(inputVO);
如果需要其他指导,请发布服务和绑定部分。您应该查看名为App.config或Web.config的文件。不要深入研究Service References文件夹,因为这是用于内部簿记的,而不是我在app.config中尝试的任何东西。我能理解的最接近的是,但仍然没有通过安全标题。。。。
<bindings>
<basicHttpBinding>
<binding name="MyWebServiceProxyPortBinding">
<security mode="Message" clientCredentialType="UserName" />
</binding>
</basicHttpBinding>
</bindings>
var securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityElement.AllowInsecureTransport = true;
securityElement.EnableUnsecuredResponse = true;
var encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
var transportElement = new HttpTransportBindingElement();
var binding = new CustomBinding(securityElement, encodingElement, transportElement);
ServiceReference1.MyWebServiceProxyClient client = new ServiceReference1.MyWebServiceProxyClient();
ServiceReference1.getAddressFormatInput inputVO = new ServiceReference1.getAddressFormatInput();
ServiceReference1.getAddressFormatOutput outputVO = new ServiceReference1.getAddressFormatOutput();
client.Endpoint.Binding = binding;
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";
inputVO.addressNumber = 13602;
inputVO.addressNumberSpecified = true;
outputVO = client.GetAddressFormat(inputVO);