如何设置aspnet核心Soap Response名称空间

时间:2019-01-22 10:54:05

标签: c# soap namespaces

我已经使用Soap-Core(aspnet核心)创建了一个服务器端SOAP端点。 但是我需要为响应设置名称空间(请求进展顺利)。

所以,我有这份服务合同:

    public interface IToaProducerService
    {
        [OperationContract(Name = "send_message", Action = "agent_service/send_message")]
        [return: MessageParameter(Name = "send_message_response")]
        List<MessageResponseDTO> send_message(UserDTO user, MessagesDTO messages);
    }

有了这个,我得到以下回应:

<s:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <send_messageResponse xmlns="urn:toatech:agent">
         <send_message_response>
            <MessageResponseDTO>
               <message_id>3138306</message_id>
               <status>sent</status>
            </MessageResponseDTO>
         </send_message_response>
      </send_messageResponse>
   </s:Body>
</s:Envelope>

但是我需要响应如下:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:toatech:agent">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:send_message_response>
         <urn:message_response>
            <urn:message_id>3138306</urn:message_id>
            <urn:status>sent</urn:status>
         </urn:message_response>
      </urn:send_message_response>
   </soapenv:Body>
</soapenv:Envelope>

我在startup.cs中使用了SoapSerializer.XmlSerializer app.UseSoapEndpoint<ToaProducerService>("/producer", new BasicHttpBinding(), SoapSerializer.XmlSerializer);

因此,我有一些问题需要解决:

1-send_message_response和所有子项都必须具有“ urn:”命名空间

2-我无法覆盖MessageResponseDTO名称

MessageResponseDTO:

[XmlRoot(ElementName = "message_response", Namespace = "urn:toatech:agent")]
    [XmlType(Namespace = "urn:toatech:agent")]
    public class MessageResponseDTO
    {
        [XmlElement(Namespace = "urn:toatech:agent")]
        public string message_id;

        [XmlElement(Namespace = "urn:toatech:agent")]
        public string status;

        [XmlElement(Namespace = "urn:toatech:agent")]
        public string description;
    }

对于请求,我使用了相同的方法(也将XmlRoot与名称空间和XmlElements一起使用),并且效果很好。

0 个答案:

没有答案
相关问题