如何在C#WSDL SOAP请求信封去 [英] How to go from wsdl SOAP request envelope in C#

查看:227
本文介绍了如何在C#WSDL SOAP请求信封去的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一个Web服务调用的行动,但我不知道该请求信封将是什么样子(该服务由用户在运行时附后)。



一般来说,我想编程基于WSDL链接生成SOAP信封。随着操作的给定链路获取列表和这样的结果对于具体的一个:

 < soapenv:信封的xmlns:soapenv =HTTP: //schemas.xmlsoap.org/soap/envelope/的xmlns:瓮=瓮:webservice.contentinn.com> 
< soapenv:页眉和GT;
<金塔:AuthHeaderElement>
<令牌GT;< /公司>
< /金塔:AuthHeaderElement>
< / soapenv:页眉和GT;
< soapenv:身体与GT;
<金塔:TestMethod的>
< ID和GT;< / ID>
< /金塔:TestMethod的>
< / soapenv:身体与GT;
< / soapenv:信封>



任何人有任何想法如何做到这一点?


解决方案

这个问题的答案提出了几个办法:




  • 了SoapUI :这是不是一个真正的编程方法

  • 城堡动态代理的:这是更接近你听起来像什么需要,但还是不太有

  • 这里的例子可能是你追求的:




    DynamicProxy允许你创建动态在运行时WCF客户端通过指定服务的WSDL URI。该DynamicProxy不依赖于预编译代理或配置。该DynamicProxy使用MetadataResolver从服务和WsdlImporter下载所述元数据来创建合同并在运行时绑定。编译动态代理可以用来调用使用反射服务的操作。



    这个例子显示如何动态代理来调用使用简单类型和复杂的操作类型。使用的流程如下。




    1. 创建ProxyFactory里指定服务的WSDL URI。



      DynamicProxyFactory厂=新DynamicProxyFactory(HTTP://本地主机:8080 / WcfSamples / DynamicProxy WSDL);


    2. 浏览终端,元数据,合同等。





      factory.Endpoints factory.Metadata factory.Contracts factory.Bindings 





    1. 创建DynamicProxy到通过指定端点或合同名称的终点。




      DynamicProxy代理= factory.CreateProxy(ISimpleCalculator); 







      DynamicProxy代理= factory.CreateProxy(终点); 





    1. 上调用DynamicProxy



     双重结果=(dobule)proxy.CallMethod(添加,1D,2D); 





    1. 关闭DynamicProxy




      proxy.Close(); 




    要运行该示例:编译该解决方案,运行CalculatorService.exe然后运行CalculatorDynamicClient.exe



  • 有一个Java的例子这里了。



I need to invoke action on a web service, but i have no idea what the request envelope will look like (the services are attached at runtime by users).

Generally I'd like to generate soap envelope programmatically based on wsdl link. With given link get list of operation and such result for specific one:

<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>

Anyone have idea how to do that?

解决方案

Answers to this question suggests a couple of approaches:

  • SoapUI: This is not really a programmatic approach.
  • Castle Dynamic Proxy: This is closer to what you sound like you need, but still not quite there.
  • The example here is probably what you're after:

    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, too.

这篇关于如何在C#WSDL SOAP请求信封去的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆