Connect LinqPad to WCF webservice with ?wsdl URI query
Asked Answered
G

4

17

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.

Gam answered 7/7, 2014 at 3:49 Comment(0)
P
27

Check out the following:

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

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

Prosy answered 11/7, 2014 at 14:27 Comment(4)
Thanks for the recommendation. This is definitely quicker to get running than the manual process in my own answer.Gam
I tried this against a WCF service and it did not generate anything. I got these errors: Warning> This web reference does not conform to WS-I Basic Profile v1.1. Warning> SOAP 1.1 binding was not found: WS-I's Basic Profile 1.1 consists of implementation guidelines that recommend how a set of core Web services specifications should be used together to develop interoperable Web services. For the 1.1 Profile, those specifications are SOAP 1.1, WSDL 1.1, UDDI 2.0, XML 1.0 and XML Schema. Error> No classes were generated. > Cannot create a connection.Equivalency
@MikeK: Using the "basicHttpBinding" binding solved the issue for me and I was able to add a service. Also make sure from the list you get (all available bindings) you chose the one starting with "BasicHttpBinding_"Laoag
Our services have a MessageHeader argument in the operation signatures. When adding a connection using this driver, it omits those MessageHeader argument from the operation signatures. Any ideas on how to resolve that?Dine
G
7

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.

Gam answered 11/7, 2014 at 9:8 Comment(4)
That's an interesting approach. Why the heck not just connect the way the WCF Test Client does?Equivalency
If I understand correctly, that's exactly what WCF Test Client does behind the scenes: grab the WSDL, build proxy classes, generate a UI for the user based on those. (Same for WebServiceStudio). Am I wrong?Gam
Probably. My issue is I have a service with a ton of methods that return DataTables or DataSets, which are not supported by the WCF Test Client.Equivalency
I'm quite a bit late to this party, but I cut back on these steps a little by copy/pasting the code generated from svcutil.exe into the query itself (using a C# Program type query) and adding the appropriate information in the app.config. From there, var client = new MyServiceClient(); and you're off to the races. Still somewhat of a pain, but slightly better than compiling a DLL and adding that as a reference.Soricine
S
5

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.

Showpiece answered 11/9, 2018 at 20:37 Comment(2)
This is the answer. Re: 1.: It's called svcutil.exeIsle
I exactly had this situation, where our service operations expected to have authentication using MessageHeaders. Joe's answer allowed me to add a service reference (connection), but was omitting the MessageHeader arguments from the service operations. This answer did the trick.Dine
A
1

This really depends on where your strengths are. It is not easy to judge based on the question as it only describes attempts at running automated tools. Questions at SO usually have a "what have I tried thus far" part. This is not only to encourage efforts prior to posting, but also to see what avenues could be suggested.

One big question here is if you know enough of (or are willing to read up on) the workings of the add service reference feature to reproduce it in code. Or if you can find an open source project with proper licensing to leverage it.

I would suggest that you look into writing LINQPad data extentions.

Anachronistic answered 11/7, 2014 at 9:1 Comment(1)
Thanks! Yes, given my now-improved understanding of the scope of LINQPad's built in "WCF Data Services" driver, it looks like a custom Data Context driver would be the correct way to expose these services as LINQPad Connections.Gam

© 2022 - 2024 — McMap. All rights reserved.