Partager via


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

Comments

  • Anonymous
    May 13, 2008
    What about native c++ clients? (For example, is there a tool like axis-wsdl2Java for c++?)

  • Anonymous
    March 24, 2010
    Hi I want WCF with Java client. I have downloaded axis-1_4. but i am not getting what to do now ? please help.

  • Anonymous
    August 19, 2010
    I am creating the webservice WCF with Java client using axis-wsdl2Java tool and i am getting the below error [axis-wsdl2java] java.io.IOException: Emitter failure.  There is an undefined binding (MyApi) in the WSDL document http://localhost:8888/MyAPI/service.svc?wsdl. [axis-wsdl2java] Hint: make sure <port binding=".."> is fully qualified. I saw the WDSL, and I found that there is binding element missing. But other team C# (not java) is using the same wsdl file and created the client and calling the webservice methods. This WDSL is exposed by third party vendor and they are not ready to modified the wsdl for us. So please tell is there any work around to solve this problem?

  • Anonymous
    August 22, 2010
    temparory I solved this issue with axis2 wsdl2java.bat, previously i was using axis1