【问题标题】:ASP.NET SOAP Service - Adding Extra InformationASP.NET SOAP 服务 - 添加额外信息
【发布时间】:2014-11-07 09:59:36
【问题描述】:

我创建了一个简单的 Web 服务来接收数据,但是我缺少一个来自客户端 SOAP 示例的元素,我似乎无法模拟。

下面是我的带有示例 SOAP 布局的 Web 服务:

[WebMethod]
public void ReceiveStatusUpdate(string Reference, string ThirdPartyReference, string Status)
{
}

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
            <ReceiveStatusUpdate xmlns="http://tempuri.org/">
                <Reference>string</Reference>
                <ThirdPartyReference>string</ThirdPartyReference>
                <Status>string</Status>
            </ReceiveStatusUpdate>
    </soap:Body>
</soap:Envelope>

下面是他们的 SOAP 示例,其中有一个名为 StatusUpdate 的元素:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <ReceiveStatusUpdate xmlns="http://tempuri.org/">
            <StatusUpdate>
                <Reference>zzzz</Reference>
                <ThirdPartyReference>yyyy</ThirdPartyReference>
                <Status>xxxx</Status>
            </StatusUpdate>
        </ReceiveCL4UStatusUpdate>
    </soap:Body>
</soap:Envelope>

谁能解释一下我需要补充什么:-)

【问题讨论】:

    标签: c# asp.net web-services soap


    【解决方案1】:

    上面“你的”示例中的 xmlns:soap 命名空间似乎丢失了。它的值应始终为:“http://www.w3.org/2001/12/soap-envelope”。

    命名空间将 Envelope 定义为 SOAP Envelope,如果使用不同的命名空间,通常使用应用程序会生成错误并丢弃消息。

    【讨论】:

      【解决方案2】:

      要解决缺少的元素,我需要在服务中声明一个对象,然后将每个字符串作为对象中的一个变量,请参阅下面的代码:

      namespace WebApplication1
      {
          [WebService(Namespace = "http://tempuri.org/")]
          [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
          [System.ComponentModel.ToolboxItem(false)]
      
          public class Update : WebService
          {
              [WebMethod]
              public void ReceiveStatusUpdate(Object StatusUpdate)
              {
                  var reference = StatusUpdate.Reference;
                  var thirdPartyReference = StatusUpdate.ThirdPartyReference;
                  var status = StatusUpdate.Status;
              }
      
              public class Object
              {
                  public string Reference;
                  public string ThirdPartyReference;
                  public string Status;
              }
          }
      }
      

      我希望这对其他人有用:-)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-26
        • 2018-10-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-27
        • 2020-09-24
        相关资源
        最近更新 更多