C# 调用https web服务时遇到问题

C# 调用https web服务时遇到问题,c#,web-services,soapui,C#,Web Services,Soapui,有一个web服务,我可以使用SOAPUI成功地调用,但要在VisualStudio中调用。这两个web服务客户机都是由相同的xml(wsdl和xsd)生成的,我在下面共享这些xml 下面的屏幕截图显示了我如何在SOAPUI中成功调用web服务。 当我使用相同的wsdl和xsd文件尝试相同的web服务时,出现以下错误 The content type text/html of the response message does not match the content type of the

有一个web服务,我可以使用SOAPUI成功地调用,但要在VisualStudio中调用。这两个web服务客户机都是由相同的xml(wsdl和xsd)生成的,我在下面共享这些xml

下面的屏幕截图显示了我如何在SOAPUI中成功调用web服务。

当我使用相同的wsdl和xsd文件尝试相同的web服务时,出现以下错误

The content type text/html of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 768 bytes of the response were: '<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:date="http://exslt.org/dates-and-times" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><env:Fault><faultcode>E9810004</faultcode><faultstring>Schema Validation Error</faultstring><detail>https://10.152.29.21:443/bea/ws/gi/fi/getbalsinfocallback/v01: cvc-particle 3.1: in element {http://schemas.xmlsoap.org/soap/envelope/}Body of type {http://schemas.xmlsoap.org/soap/envelope/}Body, found &lt;NS3:FIGetBalsInfoCallBackRs> (in namespace http://www.sama.bea.sa/inquiry/FIGetBalsInfo), but next item should be any of [{http://schemas.xmlsoap.org/soap/envelope/}Fault, {http://www.sama.bea.sa/inquiry/services/FIGetBalsInfo}FIGetBalsInfoCallBackRs]</detail></env:Fault></env:Body></env:Envelope>'.
响应消息的内容类型text/html与绑定的内容类型不匹配(text/xml;charset=utf-8)。如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法。响应的前768个字节是:' E9810004Schema验证Errorhttps://10.152.29.21:443/bea/ws/gi/fi/getbalsinfocallback/v01: cvc颗粒3.1:元素内{http://schemas.xmlsoap.org/soap/envelope/}类型主体{http://schemas.xmlsoap.org/soap/envelope/}正文,找到NS3:FiGetBalsInFocalBackrs>(在命名空间中http://www.sama.bea.sa/inquiry/FIGetBalsInfo),但下一项应该是[{http://schemas.xmlsoap.org/soap/envelope/}过失{http://www.sama.bea.sa/inquiry/services/FIGetBalsInfo}FIGetBalsInfoCallBackRs]”。

Web服务wsdl:

    <?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="FIGetBalsInfoCallBack"
    targetNamespace="http://www.sama.bea.sa/inquiry/services/FIGetBalsInfoCallBack" xmlns:bi="http://www.sama.bea.sa/inquiry/services/FIGetBalsInfo"
    xmlns:head="http://www.sama.bea.sa/common/Header" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wbir="http://www.sama.bea.sa/inquiry/services/FIGetBalsInfoCallBack"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:types>
        <xsd:schema>
            <xsd:import namespace="http://www.sama.bea.sa/inquiry/services/FIGetBalsInfo" schemaLocation="../services/FIGetBalsInfo.xsd" />
            <xsd:import namespace="http://www.sama.bea.sa/common/Header" schemaLocation="../../common/Header.xsd" />
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="FIGetBalsInfoCallBackRq">
        <wsdl:part element="bi:FIGetBalsInfoCallBackRq" name="parameters" />
    </wsdl:message>
    <wsdl:message name="FIGetBalsInfoCallBackRs">
        <wsdl:part element="bi:FIGetBalsInfoCallBackRs" name="parameters" />
    </wsdl:message>
    <wsdl:message name="RqHdr">
        <wsdl:part element="head:MsgHdrRq" name="header" />
    </wsdl:message>
    <wsdl:message name="RsHdr">
        <wsdl:part element="head:MsgHdrRs" name="header" />
    </wsdl:message>
    <wsdl:portType name="FIGetBalsInfoCallBack">
        <wsdl:operation name="FIGetBalsInfoCallBack">
            <wsdl:input message="wbir:FIGetBalsInfoCallBackRq" />
            <wsdl:output message="wbir:FIGetBalsInfoCallBackRs" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="FIGetBalsInfoCallBackSOAP" type="wbir:FIGetBalsInfoCallBack">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="FIGetBalsInfoCallBack">
            <soap:operation soapAction="http://www.sama.bea.sa/inquiry/FIGetBalsInfoCallBack/FIGetBalsInfoCallBack" />
            <wsdl:input>
                <soap:body use="literal" />
                <soap:header message="wbir:RqHdr" part="header" use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
                <soap:header message="wbir:RsHdr" part="header" use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="FIGetBalsInfoCallBack">
        <wsdl:port binding="wbir:FIGetBalsInfoCallBackSOAP" name="FIGetBalsInfoCallBackSOAP">
            <soap:address location="http://www.sama.bea.sa/" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

Xsd 1:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified"
    targetNamespace="http://www.sama.bea.sa/inquiry/services/FIGetBalsInfo"
    xmlns:base="http://www.sama.bea.sa/common/BaseLib"
    xmlns:bi="http://www.sama.bea.sa/inquiry/services/FIGetBalsInfo"
    xmlns:gi-lib="http://www.sama.bea.sa/inquiry/services/GeneralInquiryLib">
    <xsd:import namespace="http://www.sama.bea.sa/common/BaseLib"
        schemaLocation="../../common/BaseLib.xsd" />
    <xsd:import
        namespace="http://www.sama.bea.sa/inquiry/services/GeneralInquiryLib"
        schemaLocation="GeneralInquiryLib.xsd" />
    <xsd:element name="FIGetBalsInfoRq" type="bi:T_FIGetBalsInfoRq">
    </xsd:element>
    <xsd:element name="FIGetBalsInfoRs" type="bi:T_FIGetBalsInfoRs"></xsd:element>
    <xsd:element name="FIGetBalsInfoCallBackRq" type="bi:T_FIGetBalsInfoCallBackRq"></xsd:element>
    <xsd:element name="FIGetBalsInfoCallBackRs" type="bi:T_FIGetBalsInfoCallBackRs"></xsd:element>
    <xsd:complexType name="T_FIGetBalsInfoRq">
        <xsd:sequence>
            <xsd:element maxOccurs="1" minOccurs="1" name="Rqstr" type="base:T_Rqstr"> </xsd:element>
            <xsd:element maxOccurs="1" minOccurs="0" name="InvPrty" type="base:T_InvPrty"></xsd:element>
            <xsd:element maxOccurs="1" minOccurs="0" name="ThrdPrty" type="base:T_ThrdPrty"></xsd:element>
            <xsd:element maxOccurs="1" minOccurs="0" name="AccQry" type="gi-lib:T_AccQry"></xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="T_FIGetBalsInfoRs">
    </xsd:complexType>
    <xsd:complexType name="T_FIGetBalsInfoCallBackRq">
        <xsd:sequence>
            <xsd:element name="AcctsList" type="gi-lib:T_AcctsList" maxOccurs="1" minOccurs="0"></xsd:element>
            <xsd:element name="ShrsList" type="base:T_ShrsList" maxOccurs="1" minOccurs="0"></xsd:element>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="T_FIGetBalsInfoCallBackRs">
    </xsd:complexType>
</xsd:schema>

Xsd 2:

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.sama.bea.sa/inquiry/services/GeneralInquiryLib" elementFormDefault="qualified"
    xmlns="http://www.w3.org/2001/XMLSchema" xmlns:base="http://www.sama.bea.sa/common/BaseLib" xmlns:gi-lib="http://www.sama.bea.sa/inquiry/services/GeneralInquiryLib">
    <import schemaLocation="../../common/BaseLib.xsd" namespace="http://www.sama.bea.sa/common/BaseLib"></import>
    <complexType name="T_FIRsGetAcctsInfo">
        <sequence>
            <element name="FICode" minOccurs="1" maxOccurs="1">
                <simpleType>
                    <restriction base="string">
                        <length value="5" />
                    </restriction>
                </simpleType>
            </element>
            <element name="FIRsStatus" type="base:T_StatusCode" maxOccurs="1" minOccurs="1" ></element>
            <element name="AcctsList" type="gi-lib:T_AcctsList" maxOccurs="1" minOccurs="0"></element>
            <element name="ShrsList" type="base:T_ShrsList" maxOccurs="1" minOccurs="0"></element>
        </sequence>
     </complexType>
    <complexType name="T_FIRsGetBalsInfo">
        <sequence>
            <element name="FICode" minOccurs="1" maxOccurs="1">
                <simpleType>
                    <restriction base="string">
                        <length value="5" />
                    </restriction>
                </simpleType>
            </element>
            <element name="FIRsStatus" type="base:T_StatusCode" maxOccurs="1" minOccurs="1"></element>
            <element name="AcctsList" type="gi-lib:T_AcctsList" maxOccurs="1" minOccurs="0"></element>
            <element name="ShrsList" type="base:T_ShrsList" maxOccurs="1" minOccurs="0"></element>
        </sequence>
     </complexType>
    <complexType name="T_AccQry">
        <sequence>
            <element name="AccNum" type="base:T_AccountNumber" minOccurs="1" maxOccurs="1"></element>
            <element name="IBAN" type="base:T_Flag" minOccurs="1" maxOccurs="1"></element>
        </sequence>
    </complexType>
    <complexType name="T_AcctsList">
        <sequence>
            <element name="AccInfo" type="gi-lib:T_AccountInfo" minOccurs="1" maxOccurs="unbounded"></element>
        </sequence>
    </complexType>
    <complexType name="T_AccountInfo">
        <sequence>         
            <element name="AccNum" type="base:T_AccountNumber" minOccurs="1" maxOccurs="1"></element>
            <element name="IBAN" type="base:T_IBAN" minOccurs="0" maxOccurs="1"></element>
            <element name="AccType" minOccurs="0" maxOccurs="1">
                <simpleType>
                    <restriction base="base:T_NSPC">
                        <minLength value="1" />
                        <maxLength value="20" />
                    </restriction>
                </simpleType>
            </element>
            <element name="JntAcc" type="base:T_Flag" minOccurs="1" maxOccurs="1"></element>
            <element name="AccCur" type="base:T_AccCur" minOccurs="0" maxOccurs="1"></element>
            <element name="AccStatus" type="base:T_AccStatus" minOccurs="0" maxOccurs="1"></element>
            <element name="Inst" type="base:T_FullName" minOccurs="0" maxOccurs="1"></element>
            <element name="OpnDt" type="base:T_date" minOccurs="0" maxOccurs="1"></element>
            <element name="ClsDt" type="base:T_date" minOccurs="0" maxOccurs="1"></element>
            <element name="AvailBal" type="base:T_Balance" minOccurs="0" maxOccurs="1"></element>          
            <element name="TotBal" type="base:T_Balance" minOccurs="0" maxOccurs="1"></element>
             <element name="BalDt" type="base:T_date" minOccurs="0" maxOccurs="1"></element>
            <element name="PrdUsrsList" type="base:T_PrdUsrsLis" minOccurs="1" maxOccurs="1"></element>
           <element name="RsrvList" type="base:T_RsrvList" minOccurs="0" maxOccurs="1"></element>
        </sequence>
    </complexType>
    <complexType name="T_FIRsGetDepotsInfo">
        <sequence>
            <element name="FICode" minOccurs="1" maxOccurs="1">
                <simpleType>
                    <restriction base="string">
                        <length value="5" />
                    </restriction>
                </simpleType>
            </element>
            <element name="FIRsStatus" type="base:T_StatusCode" maxOccurs="1" minOccurs="1"></element>
            <element name="DepotsList" type="gi-lib:T_DepotsList" maxOccurs="1" minOccurs="0"></element>
        </sequence>
     </complexType>
    <complexType name="T_DepotsList">
        <sequence>
            <element name="DepotInfo" type="gi-lib:T_DepotInfo" minOccurs="1" maxOccurs="unbounded"></element>
        </sequence>
    </complexType>
    <complexType name="T_DepotInfo">
        <sequence>
            <element name="DepotNum" minOccurs="1" maxOccurs="1">
                <simpleType>
                    <restriction base="base:T_NSPC_Text">
                        <minLength value="1" />
                        <maxLength value="30" />
                    </restriction>
                </simpleType>
            </element>
            <element name="DepotType" minOccurs="0" maxOccurs="1">
                <simpleType>
                    <restriction base="base:T_AnyType">
                        <minLength value="1" />
                        <maxLength value="200" />
                    </restriction>
                </simpleType>
            </element>
            <element name="JntAcc" type="base:T_Flag" minOccurs="1" maxOccurs="1"></element>
            <element name="DepotCur" type="base:T_AccCur" minOccurs="0" maxOccurs="1"></element>
            <element name="DepotStatus" type="base:T_DepotStatus" minOccurs="0" maxOccurs="1"></element>
            <element name="DepotStrtDt" type="base:T_date" minOccurs="0" maxOccurs="1"></element>
            <element name="DepotDueDt" type="base:T_date" minOccurs="0" maxOccurs="1">
            </element>
            <element name="DepotBal" type="base:T_Balance" minOccurs="0" maxOccurs="1"></element>
            <element name="PrdUsrsList" type="base:T_PrdUsrsLis" minOccurs="1" maxOccurs="1">
            </element>
        </sequence>
    </complexType>
    <complexType name="T_FIRsGetLiabsInfo">
        <sequence>
            <element name="FICode" minOccurs="1" maxOccurs="1">
                <simpleType>
                    <restriction base="string">
                        <length value="5" />
                    </restriction>
                </simpleType>
            </element>
            <element name="FIRsStatus" type="base:T_StatusCode" maxOccurs="1" minOccurs="1"></element>
            <element name="LiabsList" type="gi-lib:T_LiabsList" maxOccurs="1" minOccurs="0"></element>
        </sequence>
     </complexType>
    <complexType name="T_LiabsList">
        <sequence>
            <element name="LiabInfo" type="gi-lib:T_LiabInfo" minOccurs="1" maxOccurs="unbounded"></element>
        </sequence>
    </complexType>
    <complexType name="T_LiabInfo">
        <sequence>
            <element name="AccNum" type="base:T_AccountNumber" minOccurs="0" maxOccurs="1"></element>
             <element name="IBAN" type="base:T_IBAN" minOccurs="0" maxOccurs="1"></element>
            <element name="LiabType" minOccurs="1" maxOccurs="1">
                <simpleType>
                    <restriction base="base:T_AnyType">
                        <minLength value="1" />
                        <maxLength value="200" />
                    </restriction>
                </simpleType>
            </element>
            <element name="LiabCur" type="base:T_AccCur" minOccurs="1" maxOccurs="1"></element>
            <element name="LiabInstsNum"  minOccurs="1" maxOccurs="1">
            <simpleType>
                    <restriction base="string">
                        <minLength value="1" />
                        <maxLength value="5" />
                        <pattern value="[0-9]+" /> 
                    </restriction>
                </simpleType>
            </element>
            <element name="InstRept" type="base:T_InstRept" minOccurs="1" maxOccurs="1"></element>
           <element name="InstReptTms" type="base:T_InstReptTms" minOccurs="1" maxOccurs="1"></element>
            <element name="InstAmt" type="base:T_BaseAmt" minOccurs="1" maxOccurs="1"></element>
            <element name="LstPymtDt" type="base:T_date" minOccurs="0" maxOccurs="1"></element>
            <element name="LiabDueDt" type="base:T_date" minOccurs="1" maxOccurs="1"></element>
            <element name="TotLiabAmt" type="base:T_Balance" minOccurs="1" maxOccurs="1"></element>
            <element name="RmngLiabAmt" type="base:T_Balance" minOccurs="1" maxOccurs="1"></element>
            <element name="PrdUsrsList" type="base:T_PrdUsrsLis" minOccurs="1" maxOccurs="1"></element>
        </sequence>
    </complexType>
    <complexType name="T_FIRsGetSafsInfo">
        <sequence>
            <element name="FICode" minOccurs="1" maxOccurs="1">
                <simpleType>
                    <restriction base="string">
                        <length value="5" />
                    </restriction>
                </simpleType>
            </element>
            <element name="FIRsStatus" type="base:T_StatusCode" maxOccurs="1" minOccurs="1"></element>
            <element name="SafsList" type="gi-lib:T_SafsList" maxOccurs="1" minOccurs="0"></element>
        </sequence>
    </complexType>
    <complexType name="T_SafsList">
        <sequence>
            <element name="SafInfo" type="gi-lib:T_SafInfo" minOccurs="1" maxOccurs="unbounded"></element>
        </sequence>
    </complexType>
    <complexType name="T_SafInfo">
        <sequence>
            <element name="SafNum" minOccurs="1" maxOccurs="1">
                <simpleType>
                    <restriction base="base:T_NSPC_Text">
                        <minLength value="1" />
                        <maxLength value="30" />
                    </restriction>
                </simpleType>
            </element>
            <element name="JntAcc" type="base:T_Flag" minOccurs="1" maxOccurs="1"></element>
            <element name="SafBrnch" minOccurs="0" maxOccurs="1">
                <simpleType>
                    <restriction base="base:T_AnyName">
                        <minLength value="1" />
                        <maxLength value="200" />
                    </restriction>
                </simpleType>
            </element>
            <element name="OpnDt" type="base:T_date" minOccurs="0" maxOccurs="1"></element>
            <element name="PrdUsrsList" type="base:T_PrdUsrsLis" minOccurs="1" maxOccurs="1">
            </element>
        </sequence>
    </complexType>
</schema>

从您的代码示例中,虽然屏幕截图很难阅读,因为它太小了,但看起来您并没有传递
infoRequestCB
,而只是传递标题。您收到的消息表明请求缺少它所需要的东西,这是显而易见的。调用
FIGetBalsInfoCallBack
时,传递body对象和标题

另外,您调用的服务看起来完全是垃圾,原因有两个:

  • 到底是谁设计了一个SOAP服务,将其所有参数都放在SOAP头中,而主体是空的
  • 它将SOAP错误格式化为
    text/html
    ,这完全是错误的
谢谢你的评论,汤姆,是的,我同意你的看法,完全是垃圾,但这是一个所有客户都应该调用的中央web服务。关于web服务,我没有任何权限。另一方面,body对象有两个部分(帐户和共享),我将它们传递给服务。(它们都是空的)您的代码没有显示这方面的证据。
FIGetBalsInfoCallBack
的参数列表是
(header,null,null)
。SOAPUI项目表示需要一个空的主体。您的代码没有设置这个,因此示例