Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect LinqPad to WCF webservice with ?wsdl URI query

I want to connect LinqPad to a WCF web service which exposes its WSDL information at a URI of the form http://server.example.com/Product/Service/Version/Soap11?wsdl. I can successfully add this URI as a Visual Studio WCF web service reference, and it works with WcfTestClient also.

The actual endpoint of the service, when connecting to invoke methods, is http://server.example.com/Product/Service/Soap11.

When I try to add the web service as a LinqPad connection, if I specify the web service's URI including the ?wsdl query, I get a LinqPad error message saying "ArgumentException: Expected an absolute, well formed http URL without a query or fragment. Parameter name: serviceRoot". If I leave out the ?wsdl query, I get a 400 Bad Request response instead.

(I get the same 400 Bad Request response when I try to create a Visual Studio web service reference, or add the service to WcfTestClient, without appending ?wsdl to the URI).

Is there anything I can change at the client end to get LinqPad to successfully connect to this web service? Or do I need to mess around with the configuration at the server end? I don't control the web services I'm trying to connect to, but I might be able to tweak some configuration files on the server if I must.

like image 576
Hydrargyrum Avatar asked Jul 07 '14 03:07

Hydrargyrum


3 Answers

Check out the following:

https://github.com/dylanmei/linqpad-soap-driver

It's a third-party LINQPad driver for SOAP-based web services.

like image 73
Joe Albahari Avatar answered Nov 13 '22 10:11

Joe Albahari


It looks like I misinterpreted the scope of LINQPad's "Add connection" feature. It's for WCF Data Services only (which implement the OData specification), not for WCF web services in general. (The difference between WCF services in general and WCF Data Services specifically wasn't previously clear to me).

The services I'm trying to connect to are WCF web services, but aren't WCF Data Service web services. It turns out that the correct way for me to consume those web services from LINQPad is to generate a proxy class code & configuration file using svcutil.exe, which can then be compiled through VS or csc.exe, and the resulting assembly is then added as a standard assembly reference in LINQPad. The proxy classes can then be used in LINQPad the same way that they are used in Visual Studio.

like image 27
Hydrargyrum Avatar answered Nov 13 '22 11:11

Hydrargyrum


I'll offer an alternative answer which will help if you're targeting a service that uses authentication. In my case the service uses Windows Auth which the linqpad soap driver does not yet support. You'll be generating the client code using svcutil.exe, compiling it to an assembly, and then creating a Linqpad query to use it.

  1. Generate your service client & config file with svcutil.exe http://mylocalsite/myservice.svc - it should produce a myservice.cs file and output.config.

  2. Compile the client code into an assembly: csc myservice.cs /target:library. You should now have myservice.dll.

  3. Create your linqpad query and go into its properties (F4). In the App.config tab set the Custom Path to the your output.config file. Under Additional References, add a reference to myservice.dll.

Your query will be very simple, something like:

var client = new MyServiceClient("BasicHttpBinding_IMyService");

var result = client.DoTheThing();

result.Dump();

client.Close();

LinqPad will likely prompt you to add a reference to System.Web.Services.

like image 4
David Peters Avatar answered Nov 13 '22 09:11

David Peters