微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WCF SOAP 客户端 .NET Core 请求被序列化为实体 Html

如何解决WCF SOAP 客户端 .NET Core 请求被序列化为实体 Html

请帮忙!

我有一个带有 .Net Core 的 SOAP WCF 客户端,它正在将请求序列化到 htmlEntity,我有接收器,这就是它向我显示的方式!

<?xml version="1.0" encoding="utf-16"?>
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Header>
    <a:Action s:mustUnderstand="1">urn:call3</a:Action>
    <a:MessageID>urn:uuid:9fb7fe14-ace1-4b5f-b055-9f389606f527</a:MessageID>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <call3 xmlns="http://ws.allianz.com">
      <xml>&lt;![CDATA[&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;chargerequest&gt;&lt;transactionnumber&gt;12345&lt;/transactionnumber&gt;&lt;authentication&gt;&lt;company&gt;COL&lt;/company&gt;&lt;partnerid&gt;CP239516&lt;/partnerid&gt;&lt;agentid&gt;CA626290&lt;/agentid&gt;&lt;partnercode&gt;CP239516&lt;/partnercode&gt;&lt;agentcode&gt;1703229&lt;/agentcode&gt;&lt;/authentication&gt;&lt;operationheaders&gt;&lt;operationtypecode&gt;TA&lt;/operationtypecode&gt;&lt;productcode&gt;1251&lt;/productcode&gt;&lt;policynumber&gt;22310792&lt;/policynumber&gt;&lt;/operationheaders&gt;&lt;effectivedate&gt;20190312&lt;/effectivedate&gt;&lt;TermDate&gt;20200311&lt;/TermDate&gt;&lt;firstbill&gt;0&lt;/firstbill&gt;&lt;successive&gt;0&lt;/successive&gt;&lt;holderdoctype&gt;C&lt;/holderdoctype&gt;&lt;holderdocnumber&gt;17326334&lt;/holderdocnumber&gt;&lt;ownerdoctype&gt;C&lt;/ownerdoctype&gt;&lt;ownerdocnumber&gt;17326334&lt;/ownerdocnumber&gt;&lt;isholderdriver&gt;S&lt;/isholderdriver&gt;&lt;isholderowner&gt;S&lt;/isholderowner&gt;&lt;isnewowner&gt;S&lt;/isnewowner&gt;&lt;risktype&gt;L0001&lt;/risktype&gt;&lt;vehicleplate&gt;BIR039&lt;/vehicleplate&gt;&lt;vehicleorigin&gt;11001&lt;/vehicleorigin&gt;&lt;vehiclefasecoldacode&gt;l&lt;/vehiclefasecoldacode&gt;&lt;vehicleyear&gt;2013&lt;/vehicleyear&gt;&lt;cap&gt;0&lt;/cap&gt;&lt;riskdata&gt;&lt;ownerborndate&gt;19691010&lt;/ownerborndate&gt;&lt;ownersex&gt;M&lt;/ownersex&gt;&lt;repowered&gt;N&lt;/repowered&gt;&lt;protectiondevicecode&gt;1&lt;/protectiondevicecode&gt;&lt;accessoriesvalue&gt;0.0&lt;/accessoriesvalue&gt;&lt;shieldingvalue&gt;0.0&lt;/shieldingvalue&gt;&lt;gassystemvalue&gt;0.0&lt;/gassystemvalue&gt;&lt;insuredvalue&gt;0.0&lt;/insuredvalue&gt;&lt;isnewvehicle&gt;N&lt;/isnewvehicle&gt;&lt;continuity&gt;N&lt;/continuity&gt;&lt;circulationareadanecode&gt;11001&lt;/circulationareadanecode&gt;&lt;/riskdata&gt;&lt;/chargerequest&gt;]]&gt;</xml>
    </call3>
  </s:Body>
</s:Envelope>

c#中的代码如下


            var b = new NetHttpBinding();
            b.Security.Mode = BasicHttpSecurityMode.Transport;
            b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
            b.TransferMode = TransferMode.StreamedRequest;
            b.MessageEncoding = NetHttpMessageEncoding.Text;
            Encoding utf8 = new UTF8Encoding();
            b.TextEncoding = utf8;

            EndpointAddress ea = new EndpointAddress("https://endpointtest/WSHttpsSoap12Endpoint/");
          
            
            AutosClonicoWSPortTypeClient clientService = new AutosClonicoWSPortTypeClient(b,ea);

            var requestInterceptor = new InspectorBehavior();
            clientService.Endpoint.EndpointBehaviors.Add(requestInterceptor);
            clientService.ClientCredentials.ClientCertificate.SetCertificate(
                StoreLocation.CurrentUser,StoreName.Root,X509FindType.FindBySerialNumber,"NumberSerial");

            await clientService.OpenAsync();

var res = await clientService.call3Async("<![CDATA[" + "<test><element>exampletest</element></test>" + "]]>");

客户端层面的合约如下

[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil","2.0.2")]
    [System.ServiceModel.ServiceContractAttribute(Namespace="http://example.com",ConfigurationName="ServiceReference2.Example")]
    [XmlSerializerFormat(Style = OperationFormatStyle.Document,Use = OperationFormatUse.Literal)]
    public interface ClonicoWSPortType
    {
        
        [System.ServiceModel.OperationContractAttribute(Action="urn:call3",ReplyAction="urn:call3Response")]
        [System.ServiceModel.FaultContractAttribute(typeof(ServiceReference2.ClonicoWSException),Action="urn:call3AutosClonicoWSException",Name="AutosClonicoWSException")]
        [return: System.ServiceModel.MessageParameterattribute(Name="return")]
        [XmlSerializerFormat(Style = OperationFormatStyle.Document,Use = OperationFormatUse.Literal)]
        System.Threading.Tasks.Task<string> call3Async(string xml);
    }

如果发生在其他人身上,我感谢您的帮助,我已尝试应用我发现的所有内容,但未能解决,非常感谢您!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。