从.NET控制台应用程序调用SOAP WCF服务

时间:2018-02-05 14:14:28

标签: xml web-services wcf soap wsdl

我有一个SOAP WCF服务地址,我想从我的控制台应用程序访问它。

我已经从服务引用中将此服务添加到我的控制台项目中,这会生成一个配置文件,如下所示

<system.serviceModel>
        <bindings>
            <customBinding>
                <binding name="ZINTWS0018binding">
                    <mtomMessageEncoding messageVersion="Soap11WSAddressing10" />
                    <httpsTransport authenticationScheme="Basic" />
                </binding>
                <binding name="ZINTWS0018binding_SOAP12">
                    <mtomMessageEncoding />
                    <httpsTransport authenticationScheme="Basic" />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="http://34sapqa6.arkas.com:8000/sap/bc/srt/rfc/sap/zintws0018/120/zintws0018service/zintws0018binding"
                binding="customBinding" bindingConfiguration="ZINTWS0018binding"
                contract="SAPServiceRef.ZINTWS0018" name="ZINTWS0018binding" />
            <endpoint address="http://34sapqa6.arkas.com:8000/sap/bc/srt/rfc/sap/zintws0018/120/zintws0018service/zintws0018binding"
                binding="customBinding" bindingConfiguration="ZINTWS0018binding_SOAP12"
                contract="SAPServiceRef.ZINTWS0018" name="ZINTWS0018binding_SOAP12" />
        </client>
    </system.serviceModel>

我已经分配了用户名和密码;

client.ClientCredentials.UserName.UserName = "***";
client.ClientCredentials.UserName.Password = "***";

当我尝试访问此服务时,我收到的错误如下;

你有什么建议吗?我在哪个方面做错了? 谢谢。

{"The content type text/xml of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<?xml version=\"1.0\" encoding=\"utf-8\"?><wsdl:definitions targetNamespace=\"urn:sap-com:document:sap:soap:functions:mc-style\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:wsoap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\" xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\" xmlns:tns=\"urn:sap-com:document:sap:soap:functions:mc-style\" xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2004/09/policy\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" xmlns:n1=\"urn:sap-com:document:sap:rfc:functions\"><wsdl:documentation><sidl:sidl xmlns:sidl=\"http://www.sap.com/2007/03/sidl\"/></wsdl:documentation><wsp:UsingPolicy wsdl:required=\"true\"/><wsp:Policy wsu:Id=\"BN_BN_ZINTWS0018binding\"><saptrnbnd:OptimizedXMLTransfer uri=\"http://xml.sap.com/2006/11/esi/esp/binxml\" xmlns:saptrnbnd=\"http://www.sap.com/webas/710/soap/features/transportbinding'."}

1 个答案:

答案 0 :(得分:0)

请检查您是否可以在浏览器中访问该地址。如果没有,则可能指出问题......