简体   繁体   English

没有合同方法的情况下从wsdl创建soap Web服务客户端

[英]Create soap web service client from wsdl with no contract methods

I'm stumped, probably because of not understanding something about soap services. 我很沮丧,可能是因为不了解肥皂服务。 When I create a service reference to the current public x12 health document submission service interface: 当我创建对当前公共x12健康文档提交服务接口的服务引用时:

http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd

I get some classes that define what the body of the soap message can be, but I can't get a client proxy generated. 我得到一些类来定义肥皂消息的正文,但是我无法生成客户端代理。

I would like to build my client with WCF, but in every example I find, they have an existing contract to generate a proxy. 我想使用WCF构建我的客户端,但是在我发现的每个示例中,他们都有一个生成代理的现有合同。 I don't have that luxury. 我没有那么奢侈。 The functions for the service are called via soap action. 该服务的功能通过肥皂动作调用。

I can manually generate the call with code similar to this post but the call is always rejected because the 'nonce is expired'. 我可以使用类似于此博文的代码手动生成呼叫,但是由于“ nonce过期”,呼叫始终被拒绝。

The examples for WCF all have a nice contract in their WSDL so it seems simple, but it's useless code as I can't create any interface (automajically). WCF的示例在其WSDL中都有一个很好的约定,因此看起来很简单,但是它是无用的代码,因为我无法(自动)创建任何接口。 For example, Rick Strahl's blog post answers many questions and seems great if you have a contract message to call . 例如, 里克·斯特拉(Rick Strahl)的博客文章回答了许多问题, 如果您要致电合同消息 ,这似乎很棒。 I would like to follow his approach but am stumped on creating the client (properly)! 我想遵循他的方法,但是(正确地)在创建客户方面感到困惑!

So, I can build a legacy soap client with WSE 3, with guidance here from MSDN but aren't we supposed to use WCF now? 因此,我可以在MSDN的指导下使用WSE 3构建旧版肥皂客户端,但是我们现在不应该使用WCF吗? Even the post tags here say WSE is a last resort option. 甚至此处的帖子标签都说WSE是不得已的选择。

Am I missing something about creating the client proxy? 我是否缺少有关创建客户端代理的内容?

So my question boils down to this: How can I create the web service client proxy for a soap service with no contracts in WCF? 因此,我的问题可以归结为: 如何为WCF中没有合同的肥皂服务创建Web服务客户端代理?

Maybe I'm not understanding something about calling soap services, and could really use some help. 也许我对打电话给肥皂服务不甚了解,确实可以使用一些帮助。

[EDIT: another thought - might I make my own manually built contract and thus generate a proxy with that? [编辑:另一种想法-我可以制作自己的人工合同并以此生成代理吗? Not sure of the effect on XML output to the soap web service..ie, would the call look normal] 不确定对输出到肥皂网络服务的XML的影响。即,调用看起来正常吗?

You can check my sample project for this wsdl https://bitbucket.org/polacekpavel/servicestacksample/src 您可以在我的示例项目中查看此wsdl https://bitbucket.org/polacekpavel/servicestacksample/src

Or you can use ChannelFactory for that http://msdn.microsoft.com/library/ms576132(v=vs.110).aspx Assume you have this interface - change it to the real one. 或者,您可以将ChannelFactory用于该http://msdn.microsoft.com/library/ms576132(v=vs.110).aspx假定您具有此接口-将其更改为真实的接口。

[ServiceContract]               
public interface IMathService
{
    [OperationContract]
    int Add(int a,int b);
}

then you can call it at runtime with custom configuration of ABC(address,binding,contract) 那么您可以在运行时使用ABC的自定义配置调用它(地址,绑定,合同)

   //define binding 
    //assume your binding using basicHttp, change it if you are using something else
    BasicHttpBinding myBinding = new BasicHttpBinding();           

    //define endpoint url (where service is deployed)
    EndpointAddress myEndpoint = new EndpointAddress("http://localhost:11234/MathService.svc"); //change to real endpoint 

    //Use channel factory instead of generated one
    ChannelFactory<IMathservice> myChannelFactory = new ChannelFactory<IMathservice>(myBinding, myEndpoint); //Change to you WCF interface
    IMathservice mathService= myChannelFactory.CreateChannel();

    //and call it            
    var result = mathService.Add(1,1); //input to your method

    ((IClientChannel)mathService).Close();
    myChannelFactory.Close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM