C# 将请求发送到WebService,我可以在fiddler中看到响应,但在我的.net代码中,它为null
我正在向Web服务发送请求。我正在用小提琴来监测结果。我确实在fiddler中看到了来自Web服务的响应。但是在我的.net代码中总是得到nullC# 将请求发送到WebService,我可以在fiddler中看到响应,但在我的.net代码中,它为null,c#,web-services,c#-4.0,C#,Web Services,C# 4.0,我正在向Web服务发送请求。我正在用小提琴来监测结果。我确实在fiddler中看到了来自Web服务的响应。但是在我的.net代码中总是得到null var svc = new ESB.publishPolicyServices(); publishPolicyResponse response = svc.publishPolicyData(req); 响应总是空的。我在想,可能不是将原始响应xml转换为publishPolicyResponse类型。这就是我不明白的原因 这是web服务端的错
var svc = new ESB.publishPolicyServices();
publishPolicyResponse response = svc.publishPolicyData(req);
响应总是空的。我在想,可能不是将原始响应xml转换为publishPolicyResponse类型。这就是我不明白的原因
这是web服务端的错误还是我的.net代码?如果您需要更多代码来找出问题所在,请告诉我
更新:
下面是我从fiddler那里得到的响应xml
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<message>success</message>
</soapenv:Body>
</soapenv:Envelope>
成功
下面是wsdl中的响应类型
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18060")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.xmlns.abc.com/abc/services/publishPolicyData/envelope/1.0")]
public partial class publishPolicyResponse {
private string messageField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string message {
get {
return this.messageField;
}
set {
this.messageField = value;
}
}
}
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("publishPolicyData", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute("publishPolicyResponse", Namespace="http://www.xmlns.abc.com/abc/services/publishPolicyData/envelope/1.0")]
public publishPolicyResponse publishPolicyData([System.Xml.Serialization.XmlElementAttribute(Namespace="http://www.xmlns.abc.com/abc/services/publishPolicyData/envelope/1.0")] publishPolicyRequest publishPolicyRequest) {
object[] results = this.Invoke("publishPolicyData", new object[] {
publishPolicyRequest});
return ((publishPolicyResponse)(results[0]));
}
//
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“4.0.30319.18060”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,命名空间=”http://www.xmlns.abc.com/abc/services/publishPolicyData/envelope/1.0")]
公共部分类publishPolicyResponse{
私有字符串消息字段;
///
[System.Xml.Serialization.xmlementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
公共字符串消息{
得到{
返回此.messageField;
}
设置{
this.messageField=值;
}
}
}
///
[System.Web.Services.Protocols.SoapDocumentMethodAttribute(“publishPolicyData”,Use=System.Web.Services.Description.SoapBindingUse.Literal,ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[返回:System.Xml.Serialization.XmlElementAttribute(“publishPolicyResponse”,命名空间=”http://www.xmlns.abc.com/abc/services/publishPolicyData/envelope/1.0")]
PublicPublishPolicyResponse publishPolicyData([System.Xml.Serialization.XmlElementAttribute(命名空间=”http://www.xmlns.abc.com/abc/services/publishPolicyData/envelope/1.0“”]publishPolicyRequest publishPolicyRequest){
object[]results=this.Invoke(“publishPolicyData”,新对象[]{
publishPolicyRequest});
返回((publishPolicyResponse)(结果[0]);
}
我想您正在尝试使用第三方服务,该服务不在您的控制之下,并且可能不是使用WCF编写的
正如您展示的XML所示,主体没有被包装。WCF在默认情况下需要此消息,因此此消息应如下所示:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<r:publishPolicyResponse xmlns:r="http://www.xmlns.abc.com/abc/services/publishPolicyData/publishPolicyResponse">
<message>success</message>
</r:publishPolicyResponse>
</soapenv:Body>
</soapenv:Envelope>
您很可能希望在单独的文件中执行此操作,如
publishPolicyResponsePartial.cs
如果需要更多代码来找出问题所在,请告诉我。
我们会这样做。如果其他一切都好的话,你提供的小部件应该可以工作。我在想,也许你必须在客户端应用程序中更新WS的代理定义?对不起,我不确定我还应该包括什么。从代码上看不是这样,但你确定没有异步完成某些操作吗?如果下载并安装soapui会发生什么?通过这个测试web服务,您可以确定问题是您的客户端代码还是web服务?您是否有权访问web服务的源代码,以便在需要时对其进行调试?您的代码是否张贴在上面的try/catch语句中?如果webservice调用不在try/catch块中,则不会失败。试图确保你没有吞下一个例外不确定把它放在哪里,但我把它放在“公共部分类publishPolicyResponse{”的正上方,仍然不起作用。@feelexit你找到它了吗?
[System.ServiceModel.MessageContractAttribute(IsWrapped = false)]