我正在尝试设置一个接受预定义传入 SOAP/XML 消息的 Web 服务。我无法控制客户端代码或发送的 SOAP 消息。我正在尝试一个简单的示例,但遇到了问题。假设这是 SOAP 消息:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<CustomerRequest xmlns="http://tempuri.org">
<Customer>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Customer>
</CustomerRequest>
</env:Body>
</env:Envelope>
我的数据合同对象:
[DataContract(Name = "Customer", Namespace = "http://tempuri.org")]
public class Customer
{
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
}
服务接口:
[ServiceContract(Namespace = "http://tempuri.org")]
public interface IService1
{
[OperationContract(Action="*")]
[WebInvoke(Method = "POST")]
bool Customer(Customer customer);
}
当我发送 SOAP 请求时,我可以在 fiddler 中查看所有内容,看起来还不错。但是当它遇到我的代码时,Customer 对象为空。我觉得我错过了一些非常简单的东西。
这也是原始请求:
POST http://127.0.0.1.:3619/Service1.svc HTTP/1.1
SOAPAction: http://tempuri.org/IService1/Customer
Content-Type: text/xml;charset=utf-8
Host: 127.0.0.1.:3619
Content-Length: 339
Expect: 100-continue
Connection: Keep-Alive
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<CustomerRequest xmlns="http://tempuri.org">
<Customer>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Customer>
</CustomerRequest>
</env:Body>
</env:Envelope>