qinking126
qinking126

Reputation: 11875

Send the request to WebService, I can see response in fiddler, but in my .net code, its 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);

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.

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.

Update:

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>

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]));
    }

Upvotes: 0

Views: 1711

Answers (1)

CodeCaster
CodeCaster

Reputation: 151586

I suppose you're trying to consume a third-party service, not under your control and probably not written using 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>

You can instruct WCF to not expect a wrapped message body by addingthe following attribute to the publishPolicyResponse class, as explained here:

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

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

Upvotes: 1

Related Questions