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

标签 c# web-services

我遇到了错误:

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

当我尝试使用以下代码调用我的网络服务时:

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

我的网络服务方法很简单,看起来像这样:

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

当我进行调用时,我知道请求不是 NULL,但是当它到达 web 服务时,它总是被接收为 null。我使用 wsdl.exe 实用程序从 WSDL 生成了 web 服务,显然我不了解我应该了解的 SOAP 的所有细节。还有其他人遇到过这个问题吗?

最佳答案

我不知道是什么原因造成的,所以这不是您问题的答案,而只是对进一步研究问题的方法的建议

尝试使用嗅探器查看机器之间发送的实际数据,找出问题出在哪一边。我用过 Wireshark成功一次。

关于c# - System.Web.Services.Protocols.SoapException : Server was unable to process request. ---> System.ArgumentNullException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/563162/

相关文章:

c# - Dns.GetHostEntry 能否返回一个地址列表为空的 IPHostEntry?

android - Retrofit返回错误307,在android中调用web服务

java - 如何验证 spring-mvc POST webservice 中的集合?

Java Web 服务和 XML

c# - 从 Active Directory 获取用户名

c# - && 和 || 是否有 "and assignment operator"速记?

c# - 如何在不将属性名称作为字符串传递的情况下引发 PropertyChanged 事件?

c# - web服务中文件下载多线程并发的问题

java - 带有状态代码的非 Jersey JAX-RS 自定义异常

javascript - 找出在 foreach 循环中按下了哪个按钮