
[英]Pass User info to WCF Web service with WCF method vs with Soap header
[英]WCF call to SOAP web service successfull but the client method returns Nothing
我正在尝试使用我们Intranet上的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>
谢谢!
因此,在尝试了两个多星期之后,我决定使用HttpWebRequest类调用该服务以自行构建请求( 示例 )。 尝试后,即使我在标题中发送用户名/密码,它也给我一个“ 401-未经授权”错误。 原来,我需要像以下那样指定凭据网络凭据:
proxy.Credentials = New System.Net.NetworkCredential(UserID, UserPassword)
现在,我可以将响应取回并准备阅读。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.