简体   繁体   中英

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException

I've been getting the error:

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException

When I try to call my webservice using the following code:

{
//Create an echoSync request - set the services.
ServiceNameType sourceService = new ServiceNameType {Service = "echoSync", OnBehalfOf = "Source"};
ServiceNameType destService = new ServiceNameType {Service = "echoSync", OnBehalfOf = "Destination"};

//Create the request.
SDD2RequestType request = new SDD2RequestType
                  {
                      AppId = "echoSync",
                      SourceService = sourceService,
                      DestService = destService,
                      RequestId = "1",
                      RequestBody = "Ping"
                  };

//Create the originator.
originator originator = new originator {id = "123456789"};

//Create the transport.
SDD2Transport transport = new SDD2Transport {originatorValue = originator};

//Send the request.
SDD2ResponseType response = null;
response = transport.SDD2TransportOp(request);

//Write out the response.
System.Console.WriteLine(response.ResponseBody.ToString());
}

My webservice method is quite simple and it looks like this:

    [System.Web.Services.Protocols.SoapHeaderAttribute("originatorValue", Direction = System.Web.Services.Protocols.SoapHeaderDirection.InOut)]
    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://memberdirect.net/SDD2/Transport", RequestElementName = "SDD2Transport", RequestNamespace = "http://cucbc.com/sdd2/transport/", ResponseElementName = "SDD2TransportResponse", ResponseNamespace = "http://cucbc.com/sdd2/transport/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Default)]
    [return: System.Xml.Serialization.XmlElementAttribute("SDD2Response", Namespace = "http://cucbc.com/sdd2/")]
    public override SDD2ResponseType SDD2TransportOp(SDD2RequestType SDD2Request)
    {
        if (SDD2Request == null) throw new ArgumentNullException("SDD2Request");
        var response = new SDD2ResponseType();

        switch (SDD2Request.AppId)
        {
            case "echoSync":
                response.AppId = SDD2Request.AppId;
                response.ProcessingStatus = ProcessingStatusType.Complete;
                response.RequestId = SDD2Request.RequestId;
                response.ResponseBody = "Pong";
                break;
            default:
                throw new System.NotImplementedException();
                break;
        }

        return response;
    }

When I make the call I know the request is not NULL but when it arrives at the webservice it is always received as null. I generated the webservice from WSDL using the wsdl.exe utility and clearly I don't understand all the details of SOAP that I should. Has anyone else run into this issue?

I had the same problem, although the cause might be different. When I stepped through my code in the debugger, the method argument went from being an instance to a null.

For the record it was caused by the RequestElementName being different to the method name. There may be other influencing factors but when I either removed the RequestElementName attribute from the method definition or I made it the same as the method name, the problem with the null argument disappeared.

For example, your code has RequestElementName = "SDD2Transport" and method name SDD2TransportOp.

Now I don't know why this should be a problem, especially as you also have: ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Default, not Wrapped, which implies that the ElementName will not be used anyway.

I wonder if this is a bug in the .NET SOAP client protocol class because what happens is that although the correct method is called in the web service (because it is identified in the SOAP Action header), the arguments do not get deserialized.

In my case I had to edit the generated C# class every time I recreated it in order to remove the RequestElementName attributes. Note that I had no control over the source WSDL as it was supplied by a 3rd party.

I have no idea what causes this so this is not an answer to your question, but only a suggestion for a way to look further into the problem

Try using a sniffer to look at the actual data being sent between the machines and find out on which side the problem is. I've used Wireshark successfully once.

I didn't have a chance to use Wireshark as Configurator suggested but I was able to resolve this issue by Updating Web Reference in the Solution Explorer.

I'm a bit chagrined at having found such a simple solution to this after having wrestled with it for over an hour but I hope that this post helps someone out there.

"parameter is received as null" almost always means that there is a difference between the qualified names expected by the server, and those being sent by the client. An XML qualified name consists of the namespace plus the local name. This usally means that the namespace is incorrect on the client side, though I've seen one report of a difference with the name.

In any case, you've found the #1 solution to the problem - "Update Web Reference".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM