发送请求到WebService,我可以看到响应在fiddler,但在我的.net代码中,它的null [英] Send the request to WebService, I can see response in fiddler, but in my .net code, its null

查看:1504
本文介绍了发送请求到WebService,我可以看到响应在fiddler,但在我的.net代码中,它的null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我向网络服务发送请求。我使用fiddler来监视结果。我没有看到从webservice在提琴手的回应。但总是在我的.net代码中获得null。

I am sending a request to the webservice. I am using fiddler to monitor the result. I did see the response back from the webservice in fiddler. but always get null in my .net code.

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

响应始终为null。我在想,也许它不会将原始响应xml转换为publishPolicyResponse类型。这是为什么我不会得到它。

response always null. I am thinking about, probably its not converting the raw response xml to publishPolicyResponse type. thats why I am not getting it.

这是一个错误在网络服务端或我的.net代码?请告诉我们您是否需要更多验证码才能找出问题所在。

is this a bug on hte web service side or my .net code? let me know if you need more codes to figure out what the problem is.

更新:

这里是从fiddler获得的响应xml。

here's the response xml I get from fiddler.

<?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中的响应类型。

here's the response type in 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]));
    }


推荐答案

消耗一个第三方服务,而不是在你的控制下,并且可能不是使用WCF编写的。

I suppose you're trying to consume a third-party service, not under your control and probably not written using WCF.

从你显示的XML看,默认情况下,WCF期望此消息,因此此消息应如下所示:

As it looks like from the XML you show, the body is not wrapped. WCF expects this by default, so this message should look like:

<?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>

您可以通过向<$ c $添加以下属性来指示WCF不要等待包装的邮件正文c> publishPolicyResponse 类,如此处

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

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

You most likely would want to do this in a separate file, like publishPolicyResponsePartial.cs.

这篇关于发送请求到WebService,我可以看到响应在fiddler,但在我的.net代码中,它的null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆