我正在尝试使用内部网上的Java Web服务。我向我的客户端项目添加了一个服务引用,我能够成功地进行调用,并且通过使用Fiddler,我能够看到来自服务的成功SOAP响应,但是WCF生成的方法返回Nothing。经过多天的研究,我发现最常见的错误是响应命名空间不匹配。所以我修改了WSDL并重新创建了引用,但该方法仍然返回Nothing。我不知道还有什么可以找。
这是WSDL文件中自动生成的响应类。
<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
以下是客户端代码:
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
我的Web.config文件上的端点配置:
<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>
通过Fiddler发送的SOAP请求:
<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>
SOAP响应:
<?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>
谢谢!
答案 0 :(得分:0)
因此,在尝试了两周以上后,我决定使用HttpWebRequest类来调用该服务来自己构建请求(example)。尝试后,它给了我一个“401 - 未经授权”的错误,即使我在标题中发送用户名/密码。事实证明我需要指定凭证网络凭证,如下所示:
proxy.Credentials = New System.Net.NetworkCredential(UserID, UserPassword)
现在我收到回复并准备好阅读。