首页 > 解决方案 > 如何在 C# 中使用肥皂网络服务并在请求中传递 XML?

问题描述

我需要你的帮助来找到在 c# 中调用肥皂网络服务的最佳方法吗?

我知道在 c# 中使用 Web 服务参考功能是一个不错的选择。

我尝试使用它,但它不起作用?

这是我要发布的xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://temenos.com/CUSTDETS">
       <soapenv:Header/>
       <soapenv:Body>
          <cus:EDBCUSTDETS>
             <WebRequestCommon>
                <!--Optional:-->
                <company></company>
                <password></password>
                <userName></userName>
             </WebRequestCommon>
             <EDBCUSTDETSType>
                <!--Zero or more repetitions:-->
                <enquiryInputCollection>
                   <columnName></columnName>
                   <criteriaValue></criteriaValue>
                   <operand>EQ</operand>
                </enquiryInputCollection>
             </EDBCUSTDETSType>
          </cus:EDBCUSTDETS>
       </soapenv:Body>
    </soapenv:Envelope>

在服务引用文件夹中添加 WSDL 的引用后,我将其命名为 ServiceReference1。

现在我可以在我的代码中看到:

如何实现这个要求?

如何添加公司、密码和用户名以及 enquiryInputCollection 参数?

有没有实现这一目标的最佳实践?

谢谢。

标签: c#soap

解决方案


如果您已经成功地生成了从 WSDL 分类的代理,那么您应该可以开始了。我假设您应该已经获得了使用它们的 Web 服务文档。

寻找service client classes开始。

例如:

var client = new ServiceReference1Client();
client. ? //(should list Methods and you can find Types of Paramaters to build them.)

如果您签入 web.config/app.config,并且如果您看到 and<client><endpoint />,这就是您提供端点地址的地方。如果您需要发送客户端证书,您可能希望从 or 开始并设置安全性,例如:

 <security mode="Transport">
    <transport clientCredentialType="Certificate" />
 </security>

有很多关于 WCF 功能的资源来实现这一点。希望这有助于交配。


推荐阅读