System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---> System.ArgumentNullException [英] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException

查看:6275
本文介绍了System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---> System.ArgumentNullException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了错误:

System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---> System.ArgumentNullException

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

当我尝试使用下面的代码来调用我的web服务:

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



我的web服务方法相当简单,它看起来是这样的:

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

当我拨打电话,我知道该请求不为空,但是当它到达在web服务它总是收到空。我生成WSDL从web服务使用Wsdl.exe用工具,并明确我不明白SOAP是我应该的所有细节。有没有其他人遇到这个问题?

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?

在此先感谢您的帮助,任何人都能够提供。

Thanks in advance for any help that anyone is able to provide.

推荐答案

我有同样的问题,虽然原因可能是不同的。当我通过我在调试代码加强,方法参数被一个实例来空去了。

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.

有关记录它是由RequestElementName造成的是不同的方法名。可能还有其他的影响因素,但是当我无论是从方法定义删除RequestElementName属性,或者我做了相同的方法名,用空参数问题就消失了。

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.

例如,您的代码RequestElementName =SDD2Transport和方法名SDD2TransportOp。

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

现在我不知道为什么,这应该是一个问题,尤其是当你还有:ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Default,不换,这意味着的ElementName不会使用反正

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.

我不知道这是否在.NET SOAP客户端协议类的错误,因为发生的事情是,虽然正确的方法是在Web服务进行调用(因为它是在SOAP动作头识别),参数没有得到反序列化。

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.

在我来说,我有我每次重新创建它的时间来编辑生成的C#类,以去除RequestElementName属性。请注意,我有超过因为它是由第三方提供的源WSDL无法控制的。

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.

这篇关于System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---> System.ArgumentNullException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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