1

所以总而言之,我正在尝试使用 C# 使用 javaspring wsse Web 服务。这就是我需要发送的 web 服务标头的样子..

<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1"
 xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-27777511"
 xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>username</wsse:Username>
<wsse:Password
 type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
 password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>

我尝试过使用 wse3.0 自定义策略断言,但没有成功。我正在使用 VS 2008。我正在使用一个基本的控制台应用程序,在使用此 Web 服务时应该没有问题。这是我的 app.config,它会在添加服务引用时自动更新

  <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="wsSoap11" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
    </system.serviceModel>
</configuration>

我调用该服务的客户端代码是:

            SecurityBindingElement securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
            securityElement.IncludeTimestamp = false;
            TextMessageEncodingBindingElement encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
            HttpTransportBindingElement transportElement = new HttpTransportBindingElement();

            CustomBinding customBinding = new CustomBinding(securityElement, encodingElement, transportElement);

            EndpointAddress endpoint = new EndpointAddress("http://11.11.22.222:8080/OpenClinica-ws/ws/studyEventDefinition/v1/studyEventDefinitionWsdl.wsdl");

            ServiceReference1.wsClient cl = new  wsClient(customBinding, endpoint);

            cl.ClientCredentials.UserName.UserName = "x";
            cl.ClientCredentials.UserName.Password = "y";

            studyRefType sr = new studyRefType();
            sr.identifier = "S_12345";

            listAllRequest la = new listAllRequest();
            la.studyEventDefinitionListAll = new studyEventDefinitionListAllType();
            la.studyEventDefinitionListAll.studyRef = sr;
            var response = cl.listAll(la);

我从这里获得了自定义绑定示例,在 C# 中以编程方式创建 WCF 客户端的标头 (wsse) 部分。端点是 http,我无法发送时间戳,因此使用它。

我收到一个错误:

'CustomBinding'。http://tempuri.org/ 'ws' 的绑定。http://openclinica.org/ws/studyEventDefinition/v1 '合约配置了需要传输级完整性和机密性的身份验证模式。然而,传输不能提供完整性和机密性。

无论如何,如果我直言不讳,我很抱歉。这是我第一次尝试使用任何 java spring webservice。如果需要,我可以提供更多信息。我宁愿在我的 .cs 文件中以编程方式进行。非常感谢您的任何想法/帮助。

4

0 回答 0