简体   繁体   中英

Strange wcf .net client behavior

I'm connecting from .net to the wcf-service written in java. Call the service method succeeds, but the return value is incorrect (It is empty, although it should not be). I tested a request using SoapUI - works correctly => the problem is not in service side. I have no idea what`s wrong with client side and how fix it.

SoapUI generated request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="SOME LINK">
           <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>
                                        <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>
           <soapenv:Body>
              <web:GetObjects>
                 <!--Optional:-->
                 <ObjectTypeCode>01</ObjectTypeCode>
                 <!--Optional:-->
                 <OkrugCode>1</OkrugCode>
                 <!--Optional:-->
                 <ObjectLink>true</ObjectLink>
                 <Offset>0</Offset>
                 <Limit>5</Limit>
              </web:GetObjects>
           </soapenv:Body>
        </soapenv:Envelope>

C#-client generated request (get from IClientMessageInspector)

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
          <s:Header>
            <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" />
            <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">SMTH</VsDebuggerCausalityData>
          </s:Header>
          <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <GetObjects xmlns="Some Link">
              <ObjectTypeCode xmlns="">01</ObjectTypeCode>
              <ObjectId xmlns="">0</ObjectId>
              <ObjectLink xmlns="">true</ObjectLink>
              <Offset xmlns="">0</Offset>
              <Limit xmlns="">5</Limit>
            </GetObjects>
          </s:Body>
        </s:Envelope>

Part of App.Config

<bindings>
        <customBinding>
            <binding name="SomeConfig">
                <security 
                  authenticationMode="UserNameOverTransport" 
                  enableUnsecuredResponse="true" 
                  includeTimestamp="false"
                  defaultAlgorithmSuite="Basic256" 
                  requireDerivedKeys="True"
                  messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"/>
                <textMessageEncoding messageVersion="Soap11" />
                <httpsTransport maxReceivedMessageSize="2147483647"/>
            </binding>
        </customBinding>
    </bindings>


    <client>
      <endpoint address="Some Link"
          binding="customBinding"
          bindingConfiguration="SomeConfig"
          contract="SomeContact"
          name="SomeName" >
      </endpoint>
    </client>

С# code

var someClient = new SomeServiceClient();
someClient.ClientCredentials.UserName.UserName = username;
someClient.ClientCredentials.UserName.Password = password;

someClient.Open();

var channel = someClient.ChannelFactory.CreateChannel(remoteAddress);
var objectsResponse = someClient.GetObjects(getObjectsRequest);

解决方案是在.net客户端中添加安全标头

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM