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/

相关文章:

java - 如何从 java 中的 web 服务获取属性文件的上下文路径?

c# - 浏览器可以访问 web 服务,但我的 C# 应用程序获取 "Could not establish trust relationship"

php - Google 通讯录广播/推送/通知/ Hook API

c# - 动态内容提供端点作为音频源,跳过不起作用或下载不起作用

c# - Winforms ToolTip 获取和更改所有分配的工具提示

c# - 我需要处置 FileStream 对象吗?

c# - 当您在 Windows 中运行 git push 命令时,控制台的标准输出重定向会发生什么

c# - 允许您限制对 DLL 的访问的属性是什么?

c# - WCF、Web 服务或 Rest

c# - 如何格式化Json输出?