Search code examples
wcfsoap-clientwse

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:

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

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). For example, Rick Strahl's blog post answers many questions and seems great if you have a contract message to call. 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? Even the post tags here say WSE is a last resort option.

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?

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]


Solution

  • You can check my sample project for this 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.

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

       //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();