这里是我的服务合同:SOAP消息反序列化问题 - 领域都有空值
[ServiceContract(Namespace = Service.Namespace)]
[XmlSerializerFormat(Style=OperationFormatStyle.Document, Use=OperationFormatUse.Literal)]
public interface IService
{
[OperationContract]
UpdateResponse Update(UpdateRequest request);
}
实施:
[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 };
}
}
消息合约:
[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; }
}
网络。配置文件(其中的一部分):
<services>
<service behaviorConfiguration="returnFaults" name="ServiceTest.Service">
<endpoint binding="basicHttpBinding" contract="ServiceTest.IService"
bindingNamespace="http://schemas.localhost.net/test" />
</service>
</services>
这里是从提琴手发送的SOAP消息(请求):
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>
更新()操作接收UpdateRequest对象,但的字段没有被设置(名称为空, Id为零)。尽管如此,回应是好的。
不太确定。要继承,您需要xmlns =“namespace”。在这里它被定义为NS1,不是默认的,因此不会被继承。 – Tisho 2012-08-01 07:11:55
我站在更正,这确实只适用于默认名称空间。 – CodeCaster 2012-08-01 07:24:01