【问题标题】:Receiving eBay SOAP notification messages接收 eBay SOAP 通知消息
【发布时间】:2018-01-05 22:59:27
【问题描述】:

我正在尝试使用 ebay 及其 SDK 接收通知。我设法找到了一个使用 ASP.net Web 服务的工作示例。但是,我希望能够在 Azure 上托管它并将其移动到 WCF 似乎是一个合适的解决方案。我已经尝试过这样做,我得到的最接近的是得到一个xml serializer 错误,如下所示:

服务器在处理请求时遇到错误。异常消息是“无法使用 XmlSerializer 反序列化具有根名称“信封”和根命名空间“http://schemas.xmlsoap.org/soap/envelope/”的 XML 正文(用于操作“GetOutBid”和合同(“IReceiver”、“urn:ebay:apis:eBLBaseComponents”)) .确保将 XML 对应的类型添加到服务的已知类型集合中。'

从我在网上看到的情况来看,这可能与数据合同的设置方式有关 - 我是 WCF 新手,所以不确定!

以下是我尝试放入 WCF 的 Web 服务的工作原理:

[WebMethod()]
[System.Web.Services.Protocols.SoapHeaderAttribute("RequesterCredentials", Direction = System.Web.Services.Protocols.SoapHeaderDirection.In)]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute(Action = "http://developer.ebay.com/notification/OutBid", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)]
public void OutBid(GetItemResponseType GetItemResponse)
{
    if (CheckSignature(GetItemResponse.Timestamp))
    {
        //Implement your own business logic here
    }
    else
    {
        //Implement your own business logic here
    }
    LogRequest(Server.MapPath("files/OutBid_" + GetItemResponse.Item.ItemID + "_" + GetItemResponse.Item.SellingStatus.BidCount.ToString() + "_" + GetItemResponse.CorrelationID + ".xml"));
}
public class student { public int rollno { get; set; } }
public class school { public student obj { get; set; } }

class Program
{
    static void Main(string[] args)
    {
        school obje = new school(); obje.obj.rollno = 2; Console.WriteLine(obje.obj.rollno);
    }
}

【问题讨论】:

    标签: c# azure wcf soap


    【解决方案1】:

    根据您的代码,我发现服务和客户端之间的协议是 SOAP。为了支持 SOAP,我们需要在 WCF 中使用 basicHttpBinding。 web.config中的protocolMapping配置部分应该是这样的。

    <protocolMapping>
      <add binding="basicHttpBinding" scheme="http"/>
    </protocolMapping>    
    

    之后,我们可以定义服务联系人和服务来处理请求。

    服务联系人可以是这样的。

    [ServiceContract]
    public interface IService1
    {
        [OperationContract(Action= "http://developer.ebay.com/notification/OutBid")]
        string OutBid(school value);
    }
    

    服务示例。

    public class Service1 : IService1
    {
        public string OutBid(school value)
        {
            return string.Format("The rollno is {0}", value.obj.rollno);
        }
    }
    

    以下是我的测试结果。

    样品请求。

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Header>
        <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://developer.ebay.com/notification/OutBid</Action>
      </s:Header>
      <s:Body>
        <OutBid xmlns="http://tempuri.org/">
          <value xmlns:d4p1="http://schemas.datacontract.org/2004/07/TestSOAP" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <d4p1:obj>
              <d4p1:rollno>2</d4p1:rollno>
            </d4p1:obj>
          </value>
        </OutBid>
      </s:Body>
    </s:Envelope>
    

    示例结果。

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Header />
      <s:Body>
        <OutBidResponse xmlns="http://tempuri.org/">
          <OutBidResult>The rollno is 2</OutBidResult>
        </OutBidResponse>
      </s:Body>
    </s:Envelope>
    

    如果您无法完成自己的工作,请发布您的示例 XML 请求内容以供进一步讨论。

    【讨论】:

    • 嗨,Amor,已经尝试了一段时间,但仍然遇到同样的错误。不完全理解为什么将学校作为参数类型,如果您不介意对此有所了解,那就太好了。非常感谢您的回复!
    • WCF 将帮助您解析请求 XML 并为您从 XML 中反序列化对象。您能否提供您的请求 XML 的格式?
    • 是的,这个链接有一个由 eBay 提供的 XML 示例:developer.ebay.com/Devzone/guides/ebayfeatures/Notifications/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-03
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多