【问题标题】:Send the request to WebService, I can see response in fiddler, but in my .net code, its null将请求发送到 WebService,我可以在提琴手中看到响应,但在我的 .net 代码中,它为空
【发布时间】:2014-02-13 16:32:34
【问题描述】:

我正在向网络服务发送请求。我正在使用提琴手来监控结果。我确实在提琴手中看到了来自网络服务的响应。但在我的 .net 代码中总是为 null。

var svc = new ESB.publishPolicyServices();
publishPolicyResponse response = svc.publishPolicyData(req);

响应始终为空。我正在考虑,可能它没有将原始响应 xml 转换为 publishPolicyResponse 类型。这就是为什么我没有得到它。

这是 hte web 服务端的错误还是我的 .net 代码?如果您需要更多代码来找出问题所在,请告诉我。

更新:

这是我从提琴手那里得到的响应 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]));
    }

【问题讨论】:

  • let me know if you need more codes to figure out what the problem is. 我们愿意。如果其他一切正常,您提供的小块应该可以工作。我在想,也许您必须在客户端应用程序中更新 WS 的代理定义?
  • 抱歉,不知道我还应该包括什么。
  • 从代码上看不像,但你确定某些事情没有异步完成吗?
  • 下载并安装soapui会发生什么?通过它测试网络服务,您可以确定问题是您的客户端代码还是网络服务?
  • 您是否有权访问 Web 服务的源代码,以便在需要时对其进行调试?您的代码是否在上面的 try/catch 语句中发布?如果 Web 服务调用不在 try/catch 块中,是否会失败。试图确保你没有吞下异常

标签: c# web-services c#-4.0


【解决方案1】:

我想您正在尝试使用不受您控制且可能不是使用 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>

您可以通过将以下属性添加到 publishPolicyResponse 类来指示 WCF 不期望包装的消息正文,如 here 所述:

[System.ServiceModel.MessageContractAttribute(IsWrapped = false)]

您很可能希望在单独的文件中执行此操作,例如 publishPolicyResponsePartial.cs

【讨论】:

  • 不知道放在哪里,但是我把它放在“public partial class publishPolicyResponse {”上面,还是不行。
  • @feelexit 你明白了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多