无法调用 Simple Soap 服务? [英] Unable to Call Simple Soap Service?

查看:27
本文介绍了无法调用 Simple Soap 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在问之前我已经尝试了一切.我有一个非常简单的服务,网址为 https://something.我可以使用 https://something?wsdl 获取 WSDL.现在我添加了对服务引用和 Web 引用的引用.但是当我调用它时,没有发送 SOAP 标头(用 Fiddler 检查).我可以使用 SOAP UI 调用它而不会出错.(顺便说一句,服务器正在使用 WS-Security).这是 SOAP UI 请求的一瞥,

I have tried everything before asking. I have a very simple service with url https://something. I can get WSDL using https://something?wsdl. Now I added reference this with Service Reference as well as Web Reference. But when I call it no SOAP header is sent(checked with Fiddler). I can call it with SOAP UI with no error. (BTW server is using WS-Security). Here is glimpse of SOAP UI request,

    <soapenv:Envelope xmlns:ns=""http://www.customs.pcfc.com/Schema/Declaration/TraderInboundServiceParameters/1.0"" xmlns:ns1=""http://www.customs.pcfc.com/Schema/Common/2.0"" xmlns:sad=""http://www.customs.pcfc.com/Schema/Declaration/SAD"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
       <soapenv:Header>
    <wsse:Security soapenv:mustUnderstand=""1"" xmlns:wsse=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd""><wsse:BinarySecurityToken EncodingType=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"" ValueType=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"" wsu:Id=""CertId-1270251257"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"">xxx</wsse:BinarySecurityToken><ds:Signature Id=""Signature-847101547"" xmlns:ds=""http://www.w3.org/2000/09/xmldsig#"">
    <ds:SignedInfo>

    <ds:CanonicalizationMethod Algorithm=""http://www.w3.org/2001/10/xml-exc-c14n#""/>
    <ds:SignatureMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#rsa-sha1""/>
    <ds:Reference URI=""#id-2038872614"">
    <ds:Transforms>
    <ds:Transform Algorithm=""http://www.w3.org/2001/10/xml-exc-c14n#""/>
    </ds:Transforms>
    <ds:DigestMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#sha1""/>
    <ds:DigestValue>xx</ds:DigestValue>
    </ds:Reference>
    </ds:SignedInfo>
    <ds:SignatureValue>
   xxx
    </ds:SignatureValue>
    <ds:KeyInfo Id=""KeyId-1608734597"">
    <wsse:SecurityTokenReference wsu:Id=""STRId-161586721"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd""><wsse:Reference URI=""#CertId-1270251257"" ValueType=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3""/></wsse:SecurityTokenReference>
    </ds:KeyInfo>
    </ds:Signature></wsse:Security></soapenv:Header>
       <soapenv:Body wsu:Id=""id-2038872614"" xmlns:wsu=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"">
Body
    </soapenv:Body>
    </soapenv:Envelope>

正文也是 XML.现在我已经试过了,

Body is XML as well. Now I have tried this,

        var client = new WebServiceClient();
        var reader = new XmlSerializer(typeof(Request));
        var file = new StreamReader("a.xml");
        var fileData = (DeclarationRequest)reader.Deserialize(file);
        var cert = new X509Certificate2("Mycert.cer", "Pass");
        client.ClientCertificates.Add(cert);
        fileData.UNB.DateTime = DateTime.UtcNow;
        var b = client.process(fileData);

我收到了无效证书.

然后我尝试了服务引用,

Then I tried Service Reference,

        var client = new MyClient();
        client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.TrustedPublisher, X509FindType.FindByIssuerName, "Iss Name");
        var reader = new XmlSerializer(typeof(Request));
        var file = new StreamReader("a.xml");
        var fileData = (Request)reader.Deserialize(file);
        var request = fileData;
        request.UNB.DateTime = DateTime.UtcNow;
        ((BasicHttpBinding)client.Endpoint.Binding).Security.Mode = BasicHttpSecurityMode.Transport;
        ((BasicHttpBinding)client.Endpoint.Binding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

        var response = client.process(request);

我得到了(再次无效证书),

内容类型application/soap+xml;charset=UTF-8;action="process" 响应消息与绑定的内容类型不匹配 (text/xml; charset=utf-8).如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法.响应的前 695 个字节是:

'<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
   <env:Header>
   </env:Header>
   <env:Body>
      <env:Fault><env:Code>
            <env:Value>env:Receiver
            </env:Value>
            <env:Subcode>
               <env:Value xmlns:fault="http://tempuri.org/soapfaults">fault:MessageBlocked
               </env:Value>
            </env:Subcode>
         </env:Code><env:Reason>
            <env:Text xml:lang="en">Invalid Certificate
            </env:Text>
         </env:Reason><env:Detail xmlns:fault="http://tempuri.org/soapfaults" fault:type="faultDetails">
         </env:Detail>



      </env:Fault>
   </env:Body>
</env:Envelope>'.

推荐答案

我按照 http://webservices20.blogspot.ae/2012/06/12-common-wcf-interop-confusions.html

简而言之,我有,

[ServiceContractAttribute(ConfigurationName="ServiceSoap",ProtectionLevel=ProtectionLevel.Sign)]

    <bindings>
        <customBinding>
            <binding name="BPELProcess1Binding">
                <security authenticationMode="MutualCertificate" enableUnsecuredResponse="true" 
       messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
                <textMessageEncoding messageVersion="Soap11" />
                <httpsTransport />
            </binding>
        </customBinding>
    </bindings>

    <behaviors>
        <endpointBehaviors>
            <behavior name="secureBehaviour">
                <clientCredentials>
                    <serviceCertificate>
                        <defaultCertificate findValue="My CA" storeLocation="CurrentUser" storeName="TrustedPublisher" x509FindType="FindByIssuerName" />
                    </serviceCertificate>
                </clientCredentials>
            </behavior>
        </endpointBehaviors>

    <client>
        <endpoint address="MyUrl" binding="customBinding" bindingConfiguration="BPELProcess1Binding" contract="MyContract" name="DeclarationB2BProcessing" behaviorConfiguration="secureBehaviour">
            <identity>
                <dns value="MyCertProp" />
            </identity>
        </endpoint>
    </client>

这篇关于无法调用 Simple Soap 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆