gpt4 book ai didi

c# - WCF 不反序列化。为什么我的参数是 NULL?

转载 作者:数据小太阳 更新时间:2023-10-29 01:58:35 25 4
gpt4 key购买 nike

我正在尝试设置一个 Web 服务来接受预定义的传入 SOAP/XML 消息。我无法控制客户端代码或发送的 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; }
}

服务接口(interface):

[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>

最佳答案

我在您的界面或服务实现中看不到任何提及 CustomerRequest 的地方。我认为 SOAP 请求应该发送 Customer 而不是 CustomerRequest。您可以使用 SOAPUI 并根据您的 WSDL 生成示例请求来验证这一点。将告诉您请求实际上应该是什么样子。

关于c# - WCF 不反序列化。为什么我的参数是 NULL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12701562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com