简体   繁体   English

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

[英]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.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---> System.ArgumentNullException ---> System.ArgumentNullException

When I try to call my webservice using the following code: 当我尝试使用以下代码调用我的web服务时:

{
//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: 我的webservice方法很简单,看起来像这样:

    [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. 当我进行调用时,我知道请求不是NULL,但是当它到达webservice时,它总是被接收为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. 我使用wsdl.exe实用程序从WSDL生成了web服务,显然我不了解SOAP的所有细节。 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. 对于记录,它是由RequestElementName与方法名称不同引起的。 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属性或者使其与方法名称相同时,null参数的问题就消失了。

For example, your code has RequestElementName = "SDD2Transport" and method name SDD2TransportOp. 例如,您的代码具有RequestElementName =“SDD2Transport”和方法名称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. 现在我不知道为什么这应该是一个问题,特别是因为你也有:ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Default,而不是Wrapped,这意味着无论如何都不会使用ElementName。

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. 我想知道这是否是.NET SOAP客户端协议类中的错误,因为发生的事情是尽管在Web服务中调用了正确的方法(因为它在SOAP Action标头中被标识),但参数不会被反序列化。

In my case I had to edit the generated C# class every time I recreated it in order to remove the RequestElementName attributes. 在我的情况下,我每次重新创建它时都必须编辑生成的C#类,以便删除RequestElementName属性。 Note that I had no control over the source WSDL as it was supplied by a 3rd party. 请注意,我无法控制源WSDL,因为它是由第三方提供的。

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. 我成功使用过Wireshark一次。

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. 我没有机会使用Wireshark作为Configurator建议但我能够通过在解决方案资源管理器中更新Web引用来解决此问题。

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. XML限定名称由命名空间和本地名称组成。 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". 在任何情况下,您都找到了问题的第一解决方案 - “更新Web参考”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows 2008 R2企业版问题(消息:System.Web.Services.Protocols.SoapException:服务器无法处理请求) - Windows 2008 R2 Enterprise Edition Issues(Message:System.Web.Services.Protocols.SoapException: Server was unable to process request) System.Web.Services.Protocols.SoapException:服务器无法识别HTTP标头SOAPAction的值: - System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: System.AggregateException:发生一个或多个错误。 ---> System.Web.Services.Protocols.SoapException - System.AggregateException: One or more errors occurred. ---> System.Web.Services.Protocols.SoapException SpriteBatch System.ArgumentNullException - SpriteBatch System.ArgumentNullException System.ArgumentNullException - System.ArgumentNullException NServiceBus System.ArgumentNullException - NServiceBus System.ArgumentNullException System.Web.Mvc.dll中发生System.ArgumentNullException - System.ArgumentNullException occured in System.Web.Mvc.dll 单元测试中的System.ArgumentNullException - System.ArgumentNullException in unit testing 生成的代码背后抛出System.ArgumentNullException - Generated Code Behind Throws System.ArgumentNullException 没有参数时的WCF System.ArgumentNullException - WCF System.ArgumentNullException when there's no argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM