通过WSDL“内部错误”访问Web服务

时间:2018-07-16 17:26:23

标签: c# wcf soap

已为我提供了用于Web服务的此WSDL:https://ws.conf.ebs.health.gov.on.ca:1444/HCVService/HCValidationService?wsdl

我已使用此代码生成请求消息:

public CustomXML(){
        Console.WriteLine("Creating headers and requests");
        //EBS Header
        ebs_header ebshead = new ebs_header
        {
            AuditId = audit,
            SoftwareConformanceKey = confkey
        };

        //MSA Header - EMPTY since only IDP is being used
        msa_header msahead = new msa_header();

        //IDP Header
        idp_header idphead = new idp_header
        {
            ServiceUserMUID = mohID
        };

        //request
        hcvRequest request1 = new hcvRequest
        {
            versionCode = code,
            healthNumber = healthnum
        };
        hcvRequest[] req = new hcvRequest[1];
        req[0] = request1;

        //instantiating SOAP message security
        Console.WriteLine("Creating custom security");
        if (System.Net.ServicePointManager.SecurityProtocol == (SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls))
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
        AsymmetricSecurityBindingElement sec = (AsymmetricSecurityBindingElement)SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10);
        sec.EndpointSupportingTokenParameters.Signed.Add(new UserNameSecurityTokenParameters());
        sec.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic256Sha256Rsa15;
        sec.AllowSerializedSigningTokenOnReply = true;
        sec.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
        sec.IncludeTimestamp = true;
        sec.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
        sec.EnableUnsecuredResponse = true;

        //Custom message binds
        Console.WriteLine("Instantiating custom binds");
        ICollection<BindingElement> bindingElements = new List<BindingElement>();

        Console.WriteLine("Adding custom binds");
        bindingElements.Add(sec);
        bindingElements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8));
        bindingElements.Add(new HttpsTransportBindingElement());
        CustomBinding bindings = new CustomBinding(bindingElements);
        bindings.SendTimeout = new TimeSpan(0, 10, 0);

        //Instantiate client
        Console.WriteLine("Instantiating client!!");
        EndpointAddress serviceAddress = new EndpointAddress(new Uri("https://ws.conf.ebs.health.gov.on.ca:1444/HCVService/HCValidationService?wsdl"), new DnsEndpointIdentity("ws.conf.ebs.health.gov.on.ca"), new AddressHeaderCollection());
        HCValidationClient client = new HCValidationClient(bindings, serviceAddress);

        client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode =System.ServiceModel.Security.X509CertificateValidationMode.None;
        client.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(@".p12 directory", "password");
        client.ClientCredentials.ServiceCertificate.DefaultCertificate = new X509Certificate2(@".crt directory");
        client.ClientCredentials.UserName.UserName = userID;
        client.ClientCredentials.UserName.Password = password;
        client.Open();
        //ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OnValidationCallback);

        Console.WriteLine("Results:");
        hcvRequest request = new hcvRequest();
        request.healthNumber = healthnum;
        request.versionCode = code;

        hcvResults results = null;
        try
        {
            results = client.validate(ebshead, msahead,idphead, req, "en");
        } catch (FaultException ex)
        {
            throw ex;
        }

        client.Close();
    }

会生成以下消息:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
    <h:EBS u:Id="_2" 
        xmlns:h="http://ebs.health.ontario.ca/" 
        xmlns="http://ebs.health.ontario.ca/" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <SoftwareConformanceKey xmlns=""></SoftwareConformanceKey>
        <AuditId xmlns=""></AuditId>
    </h:EBS>
    <h:IDP u:Id="_3" 
        xmlns:h="http://idp.ebs.health.ontario.ca/" 
        xmlns="http://idp.ebs.health.ontario.ca/" 
        xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <ServiceUserMUID xmlns=""></ServiceUserMUID>
    </h:IDP>
    <h:MSA u:Id="_4" 
        xmlns:h="http://msa.ebs.health.ontario.ca/" 
        xmlns="http://msa.ebs.health.ontario.ca/" 
        xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"></h:MSA>
    <ActivityId CorrelationId="590c1d8e-679c-4bdb-84de-ff909808c366" 
        xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
    <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPoxLt628TlHRAlhRoJAJ0WgYAAAAAXxLqJUf8k02/CnAvb/CH5Zjc/QBVJHpNuAjJltYUMMkACQAA</VsDebuggerCausalityData>
    <o:Security s:mustUnderstand="1" 
        xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <u:Timestamp u:Id="uuid-c3055260-d9a4-44c5-aa2f-cdaaf9690457-1" 
            xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <u:Created>2018-07-16T15:32:21.524Z</u:Created>
            <u:Expires>2018-07-16T15:37:21.524Z</u:Expires>
        </u:Timestamp>
        <o:BinarySecurityToken>
            <!-- Removed-->
        </o:BinarySecurityToken>
        <o:UsernameToken u:Id="uuid-6224c7f6-6972-4950-8133-b903684f4ce2-1" 
            xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <o:Username>
                <!-- Removed-->
            </o:Username>
            <o:Password>
                <!-- Removed-->
            </o:Password>
        </o:UsernameToken>
        <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
            <SignedInfo>
                <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></CanonicalizationMethod>
                <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"></SignatureMethod>
                <Reference URI="#_1">
                    <Transforms>
                        <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform>
                    </Transforms>
                    <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod>
                    <DigestValue></DigestValue>
                </Reference>
                <Reference URI="#_2">
                    <Transforms>
                        <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform>
                    </Transforms>
                    <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod>
                    <DigestValue></DigestValue>
                </Reference>
                <Reference URI="#_3">
                    <Transforms>
                        <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform>
                    </Transforms>
                    <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod>
                    <DigestValue></DigestValue>
                </Reference>
                <Reference URI="#_4">
                    <Transforms>
                        <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform>
                    </Transforms>
                    <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod>
                    <DigestValue></DigestValue>
                </Reference>
                <Reference URI="#uuid-c3055260-d9a4-44c5-aa2f-cdaaf9690457-1">
                    <Transforms>
                        <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform>
                    </Transforms>
                    <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod>
                    <DigestValue></DigestValue>
                </Reference>
                <Reference URI="#uuid-6224c7f6-6972-4950-8133-b903684f4ce2-1">
                    <Transforms>
                        <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform>
                    </Transforms>
                    <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"></DigestMethod>
                    <DigestValue></DigestValue>
                </Reference>
            </SignedInfo>
            <SignatureValue></SignatureValue>
            <KeyInfo>
                <o:SecurityTokenReference>
                    <o:Reference ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" URI="#uuid-6224c7f6-6972-4950-8133-b903684f4ce2-3"></o:Reference>
                </o:SecurityTokenReference>
            </KeyInfo>
        </Signature>
    </o:Security>
</s:Header>

有人知道堆栈跟踪返回的原因吗?

System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime操作,ProxyRpc&rpc) System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔型单向,ProxyOperationRuntime操作,Object [] ins,Object [] outs,TimeSpan超时) System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作) System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息) System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型) EBS_HCV.ServiceReference1.HCValidation.validate(validateRequest请求) EBS_HCV.ServiceReference1.HCValidationClient.EBS_HCV.ServiceReference1.HCValidation.validate(validateRequest请求) EBS_HCV.ServiceReference1.HCValidationClient.validate(ebs_header EBS,msa_header MSA,idp_header IDP,hcvRequest []请求,字符串语言环境) EBS_HCV.EBS_settings.CustomXML() EBS_HCV.Program.Main(String [] args)

0 个答案:

没有答案