简体   繁体   中英

WCF call to SOAP web service successfull but the client method returns Nothing

I am trying to consume a Java web service that is on our intranet. I added a Service Reference to my client project and I am able to successfully make calls and by using Fiddler I am able to see the successfull SOAP response from the service but the method generated by WCF is returning Nothing. After many days of researching, the most common fault I found is a mismatch on the namespace of the response. So I modified the WSDL and recreated the reference but the method still returns Nothing. I don't know what else to look for.

Here is the auto-generated response class from the WSDL file.

<System.Diagnostics.DebuggerStepThroughAttribute(),  _
 System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"),  _
 System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced),  _
 System.ServiceModel.MessageContractAttribute(WrapperName:="terminateCredentialRecordBySSNResponse", WrapperNamespace:="service.credential.epecs", IsWrapped:=true)>  _
Partial Public Class terminateCredentialRecordBySSNResponse

    <System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="service.credential.epecs", Order:=0, Name:="return"), _
     System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable:=True)> _
    Public [return] As EpecsCredServ.[return]

    Public Sub New()
        MyBase.New
    End Sub

    Public Sub New(ByVal [return] As EpecsCredServ.[return])
        MyBase.New
        Me.[return] = [return]
    End Sub
End Class

Here is the client code:

Dim ws As New EpecsCredentialServicePortTypeClient("EpecsCredentialServiceHttpSoap11Endpoint")
        Dim wsparams As New params

        With wsparams
            .ssn = TextBox1.Text
            .fascnPOA = "5"
            .lModSSAPIN = "9e1365"
            .credRevokeTrans = "css113655"
            .credRevokeReason = "396"
            .termActDate = Now.ToShortDateString
            .credRevokeReasonOther = "css"
        End With

        Dim results As [return] = ws.terminateCredentialRecordBySSN(wsparams) '<== returns Nothing

        If results IsNot Nothing Then
            txtResponse.Text = results.status
        End If

Endpoint configuration on my Web.config file:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="EpecsCredentialServiceSoap11Binding" />
      </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://xxx.xxx.xxx:80/axis2_epecs/services/EpecsCredentialService.EpecsCredentialServiceHttpSoap11Endpoint/"
          binding="basicHttpBinding" bindingConfiguration="EpecsCredentialServiceSoap11Binding"
          contract="EpecsCredServ.EpecsCredentialServicePortType" name="EpecsCredentialServiceHttpSoap11Endpoint">
            <headers>
                <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                    <wsse:UsernameToken wsu:Id="UsernameToken-4" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                        <wsse:Username>MYUSERNAME</wsse:Username>
                        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MYPASSWORD</wsse:Password>
                    </wsse:UsernameToken>
                </wsse:Security>
            </headers>
        </endpoint>
            </client>
  </system.serviceModel>

The SOAP request sent as seen through Fiddler:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <ActivityId CorrelationId="c057bd17-4f9d-4f98-848e-e1ba8522727a" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">ffc51799-9c34-43c2-bbac-9c49067f5f40</ActivityId>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsse:UsernameToken wsu:Id="UsernameToken-4" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:Username>MYUSERNAME</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MYPASSWORD</wsse:Password>
      </wsse:UsernameToken>
    </wsse:Security>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <terminateCredentialRecordBySSN xmlns="service.credential.epecs">
      <params xmlns="">
        <ssn>999999999</ssn>
        <fascnPOA>5</fascnPOA>
        <lModSSAPIN>9e1365</lModSSAPIN>
        <credRevokeTrans>css113655</credRevokeTrans>
        <credRevokeReason>396</credRevokeReason>
        <termActDate>6/6/2014</termActDate>
        <credRevokeReasonOther>css</credRevokeReasonOther>
      </param
    </terminateCredentialRecordBySSN>
  </s:Body>
</s:Envelope>

And the SOAP response:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <return xmlns="service.credential.epecs">
      <status>-3</status>
      <Credentials>
        <credential>
          <cred_uid>555558</cred_uid>
          <cred_ssn>999999999</cred_ssn>
          <cred_fascn_sc>0001</cred_fascn_sc>
          <cred_fascn_cn>703608</cred_fascn_cn>
          <cred_fascn_pi>1000702718</cred_fascn_pi>
          <cred_dob>1975-03-12 00:00:00.0</cred_dob>
          <cred_first_name>Demog</cred_first_name>
          <cred_middle_name>C</cred_middle_name>
          <cred_last_name>Rgstr</cred_last_name>
          <cred_fascn_ici>1</cred_fascn_ici>
          <cred_fascn_cs>1</cred_fascn_cs>
          <cred_fascn_oc>1</cred_fascn_oc>
          <cred_fascn_oi>2800</cred_fascn_oi>
          <cred_fascn_poa>5</cred_fascn_poa>
          <cred_fascn_b64>0gQQ2CEMLcDloRWhaFoBCHgUcgKCBBDX5w==</cred_fascn_b64>
          <cred_fascn_ac>2800</cred_fascn_ac>
          <cred_cert_profile>OBERTHUR_PIV_NOLOGICAL</cred_cert_profile>
          <cred_status>44</cred_status>
          <cred_sponsor_name>Max</cred_sponsor_name>
          <cred_approval_transaction>EPECS9000007</cred_approval_transaction>
          <cred_revoke_transaction>CSS20140425121200</cred_revoke_transaction>
          <cred_term_code>396</cred_term_code>
          <cred_reason_code>1</cred_reason_code>
          <cred_pacs_badge_num>28000000000</cred_pacs_badge_num>
          <cred_unqualified_cert_dn>cn=DemoRgstr (affiliate),ou=XXXXXXXX,ou=XXX,o=XXXXXX,c=US</cred_unqualified_cert_dn>
          <cred_qualified_cert_dn>cn=Demo-Rgstr (affiliate) + dnQualifier=XXX,ou=XXXXXX,ou=XXX,o=XXXXXXXX,c=US</cred_qualified_cert_dn>
          <cred_doors_code>AXX</cred_doors_code>
          <cred_term_date>2014-04-25 00:00:00.0</cred_term_date>
          <cred_mod_date>2014-04-25 15:14:12.0</cred_mod_date>
          <cred_exp_date>2013-05-22 14:31:06.505941</cred_exp_date>
          <cred_last_update_pin>9e1365</cred_last_update_pin>
          <cred_last_update_date>2014-04-25 15:14:12.405946</cred_last_update_date>
          <cred_term_code_other>CSS</cred_term_code_other>
        </credential>
        <credential />
      </Credentials>
    </return>
  </soapenv:Body>
</soapenv:Envelope>

Thanks!

So, after trying for more than two weeks I decided to call the service using the HttpWebRequest class to build the request myself ( example ). After trying, it gave me a "401 - Unauthorized" error even though I was sending the Username/Password in the header. Turns out I needed to specify the credentials Network credentials like so:

proxy.Credentials = New System.Net.NetworkCredential(UserID, UserPassword)

Now I am getting the response back and ready to read.

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