c# - 如何从 C# 中的 wsdl SOAP 请求信封

标签 c# soap wsdl

我需要调用 Web 服务上的操作,但我不知道请求信封会是什么样子(服务在运行时由用户附加)。

通常,我希望基于 wsdl 链接以编程方式生成 soap 信封。使用给定的链接获取操作列表和特定操作的结果:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:webservice.contentinn.com">
    <soapenv:Header>
        <urn:AuthHeaderElement>
            <token></company>
        </urn:AuthHeaderElement>
    </soapenv:Header>
    <soapenv:Body>
      <urn:TestMethod>
         <id></id>
      </urn:TestMethod>
    </soapenv:Body>
</soapenv:Envelope>

有人知道怎么做吗?

最佳答案

Answers to this question提出了几种方法:

  • SoapUI : 这不是真正的程序化方法。
  • Castle Dynamic Proxy :这更接近您所需要的,但还不够。
  • The example here可能是您想要的:

    The DynamicProxy allows you to create the dynamic WCF client at runtime by specifying the WSDL URI of the service. The DynamicProxy does not depend on the precompiled proxy or configuration. The DynamicProxy uses the MetadataResolver to download the metadata from the service and WsdlImporter to create the contract and binding at runtime. The compiled dynamic proxy can be used to invoke the operations on the service using reflection.

    The example shows how you can the dynamic proxy to invoke operations that use simple types and complex types. The flow of usage is as following.

    1. Create the ProxyFactory specifying the WSDL URI of the service.

      DynamicProxyFactory factory = new DynamicProxyFactory("http://localhost:8080/WcfSamples/DynamicProxy?wsdl");

    2. Browse the endpoints, metadata, contracts etc.

    factory.Endpoints factory.Metadata factory.Contracts factory.Bindings
    
    1. Create DynamicProxy to an endpoint by specifying either the endpoint or contract name.
    DynamicProxy proxy = factory.CreateProxy("ISimpleCalculator");
    

    OR

    DynamicProxy proxy = factory.CreateProxy(endpoint); 
    
    1. Invoke operations on the DynamicProxy
    double result = (dobule)proxy.CallMethod("Add", 1d ,2d);
    
    1. Close the DynamicProxy
    proxy.Close();
    

    To run the example: Compile the solution, run the CalculatorService.exe and then run the CalculatorDynamicClient.exe

  • There is a Java example here ,也是。

关于c# - 如何从 C# 中的 wsdl SOAP 请求信封,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6292859/

相关文章:

c# - 测试 : How to verify that a method is called?

java - Java 中的 SOAP Web 服务客户端

visual-studio-2010 - 有人在 Windows 7 上成功安装 Nodejs Soap 吗?

java - 使用 WSDL 生成客户端代码后如何摆脱 WSDL 依赖性?

wcf - 客户端不发送SOAPAction的WSDL第一台WCF服务器

c# - 如何从 SQL Server 向 c# 控制台应用程序发出信号?

c# - 在 WPF 中验证密码框

c# - DialogResult MessageBox 禁用空格键(空格键)提交答案

android - 使用 Android 和字节数组进行 SoapUI 测试

java - 消息部分 MyClass 未被识别。 (它存在于服务 WSDL 中吗?)