Reputation: 8854
Here's my service contract:
[ServiceContract(Namespace = Service.Namespace)]
[XmlSerializerFormat(Style=OperationFormatStyle.Document, Use=OperationFormatUse.Literal)]
public interface IService
{
[OperationContract]
UpdateResponse Update(UpdateRequest request);
}
The implementation:
[ServiceBehavior(Namespace = Namespace)]
public class Service : IService
{
public const string Namespace = "http://schemas.localhost.net/test";
public UpdateResponse Update(UpdateRequest request)
{
return new UpdateResponse() { Succeeded = true };
}
}
The message contracts:
[MessageContract(WrapperNamespace = Service.Namespace)]
public class UpdateRequest
{
[MessageBodyMember]
public int Id { get; set; }
[MessageBodyMember]
public string Name { get; set; }
}
[MessageContract(WrapperNamespace = Service.Namespace)]
public class UpdateResponse
{
[MessageBodyMember]
public bool Succeeded { get; set; }
}
The web.config file (a part of it):
<services>
<service behaviorConfiguration="returnFaults" name="ServiceTest.Service">
<endpoint binding="basicHttpBinding" contract="ServiceTest.IService"
bindingNamespace="http://schemas.localhost.net/test" />
</service>
</services>
And here is the soap message (request) sent from fiddler:
POST http://localhost:10000/Service.svc HTTP/1.1
SOAPAction: "http://schemas.localhost.net/test/IService/Update"
Content-Type: text/xml; charset="utf-8"
Host: localhost:10000
Content-Length: 532
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body xmlns:NS1="http://schemas.localhost.net/test">
<NS1:UpdateRequest id="1">
<Name xsi:type="xsd:string">Abcdefg</Name><Id xsi:type="xsd:int">1</Id>
</NS1:UpdateRequest>
<parameters href="#1"/>
</SOAP-ENV:Body>
Update() operation receives an UpdateRequest object, but the fields are not set (Name is null, Id is zero). The response is ok, though.
Upvotes: 3
Views: 6358
Reputation: 8854
I was using the XmlSerializer :) But i did not decorate the members of the message with the following attribute:
[XmlElement(Form = System.Xml.Schema.XmlSchemaForm.Unqualified), MessageBodyMember]
The deserialization works now.
PS: I couldn't do what Tisho said because I don't control the client of the web service.
Upvotes: 1
Reputation: 8492
The Name and Id elements don't have namespace. So either the soap envelope is not correct, or the MessageContract is not complete. The Name/Id should look like:
<NS1:Name xsi:type="xsd:string">Abcdefg</NS1:Name><NS1:Id xsi:type="xsd:int">1</NS1:Id>
Upvotes: 3