这是我的服务合同:
[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; }
}
web.config文件(它的一部分):
<services>
<service behaviorConfiguration="returnFaults" name="ServiceTest.Service">
<endpoint binding="basicHttpBinding" contract="ServiceTest.IService"
bindingNamespace="http://schemas.localhost.net/test" />
</service>
</services>
这是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()操作接收UpdateRequest对象,但未设置字段(Name为null,Id为零)。但是回答还可以。
答案 0 :(得分:3)
Name和Id元素没有命名空间。因此,肥皂信封不正确,或者MessageContract不完整。名称/ ID应如下所示:
<NS1:Name xsi:type="xsd:string">Abcdefg</NS1:Name><NS1:Id xsi:type="xsd:int">1</NS1:Id>
答案 1 :(得分:1)
我使用的是 XmlSerializer :) 但我没有使用以下属性:
来装饰邮件的成员[XmlElement(Form = System.Xml.Schema.XmlSchemaForm.Unqualified), MessageBodyMember]
反序列化现在有效。
PS:我不能做Tisho所说的,因为我不控制网络服务的客户。