WCF service that works with different clients

I am back from a long & happy vacation and starting to write to my blog again. I was recently asked how can one make sure that a WCF proxy can work with different clients and here was my answer to them:
1. Keep your interface clean and simple. Don't push in too many Dictionary<> or other complex object types.
2. Try out your service with atleast 4 client types: 1. WCF client, 2. Asmx client, 3. Java client, 4. Php client.

How to make non-WCF client types work with a WCF service?

1. WCF with ASMX client

Convert wsdl into a typed proxy using wsdl.exe: wsdl.exe /urlkey:"MyAPIUrl" /n:"My.Api.Asmx" https://localhost:8080/MyAPI/Service.svc?wsdl /out:MyApi_asmx_proxy.cs. WCF works with asmx as it is. So, no changes would be needed.

2. WCF with Java client

For Java clients, you'll need to convert wsdl into Java proxy classes. You can use the following tool for this purpose axis-wsdl2Java tool. Download axis from this location: https://www.apache.org/dyn/closer.cgi/ws/axis/1_4/. Wsdl2Java takes your wsdl url and generates Java proxy files for your client.

If you get an error like this:

[axis-wsdl2java] java.io.IOException: Emitter failure. There is an undefined binding (MyApi) in the WSDL document https://localhost:8888/MyAPI/service.svc?wsdl.

[axis-wsdl2java] Hint: make sure <port binding=".."> is fully qualified.

Then you're probably missing the binding element in your wsdl. Go through the wsdl and make sure that you have the following elements: types, services, porttype, binding, message. Binding element could be missing if you have two endpoints under the same service element in app.config. So instead of having something like this:

<services>
<service ... >
<endpoint..1... />
<endpoint..2.../>
</service>
</services>

replace it with this:

<services>
<service..1..>
<endpoint..1../>
</service>
<service..2..>
<endpoint..2../>
</service>

Once you have a successful wsdl2Java conversion, then you can just start coding your client. Please note that you may not necessarily see the above error.

3. WCF with PHP client

PHP uses the wsdl url. You can use $client = new SoapClient($wsdlurl); And start coding the php client.

References:

1. https://msdn2.microsoft.com/en-us/library/ms751433.aspx 

2. https://www.w3schools.com/wsdl/wsdl_binding.asp

 

---Ads-by-Microsoft---