Reputation: 21
I am trying to receive notifications using ebay and their SDK. I have managed to find a working example using an ASP.net web service. However I want to be able to host this on Azure and moving this to a WCF
seems like a suitable solution. I have tried doing so and the closest I have got is getting a xml serializer
error like below:
The server encountered an error processing the request. The exception message is 'Unable to deserialize XML body with root name 'Envelope' and root namespace 'http://schemas.xmlsoap.org/soap/envelope/' (for operation 'GetOutBid' and contract ('IReceiver', 'urn:ebay:apis:eBLBaseComponents')) using XmlSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service.'
From what I have seen online, looks like it could be to do with how the datacontract should be setup - I'm new to WCF, so not sure!
Below is what is working in the web service which I'm trying to put into WCF:
[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);
}
}
Upvotes: 1
Views: 447
Reputation: 8491
Based on your code, I found that the protocol between the service and client is SOAP. To support SOAP, we need to use basicHttpBinding in WCF. The protocolMapping configuration section in web.config should be like this.
<protocolMapping>
<add binding="basicHttpBinding" scheme="http"/>
</protocolMapping>
After that, we could define the service contact and service to handle requests.
The service contact could be like this.
[ServiceContract]
public interface IService1
{
[OperationContract(Action= "http://developer.ebay.com/notification/OutBid")]
string OutBid(school value);
}
A sample of Service.
public class Service1 : IService1
{
public string OutBid(school value)
{
return string.Format("The rollno is {0}", value.obj.rollno);
}
}
Following are my test results.
Sample request.
<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>
Sample result.
<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>
If you can't finish the work on your side, please post your sample XML request content for further discussion.
Upvotes: 0