0

For my project at school I must create some SOAP web services with WCF in a C# app, in order to make it interact with a Java EE app.

I can't find any tutorial telling me how to do this with WCF. What should I do?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Rayjax
  • 7,494
  • 11
  • 56
  • 82
  • I'm sorry I didn't explain my self well enough; how can I make C# and JEE communicate with webservices ? That's what I can't find – Rayjax Dec 04 '12 at 16:48
  • 2
    Just create the **WCF web service** in C#, and expose the endpoint (the address / URL where the service exists) and the J2EE guys should be able to attach to it and create their client-side code from it. Using either `basicHttpBinding` or `wsHttpBinding` will create a SOAP enabled service – marc_s Dec 04 '12 at 16:49
  • http://stackoverflow.com/a/19900895/2866502 check this post – Shiva Saurabh Nov 11 '13 at 07:28

3 Answers3

3

Just create a WCF project in Visual Studio, and write all the code in C#. The actual problem you're going to have is making SOAP calls from Java EE.

The WCF service will be hosted in IIS not a Windows Service hosting WCF.

Tutorials on how to get started with WCF:

http://msdn.microsoft.com/en-us/library/dd936243.aspx

Enjoy!

Nuri YILMAZ
  • 4,291
  • 5
  • 37
  • 43
GxG
  • 4,491
  • 2
  • 20
  • 18
  • OK thank you very much. DO you mean that the only choice I have is to host it on IIS in order to make it usable by a remote (local network) JEE app ? WIndows Services hosting or just application hosting isn't enough ? Thanks again – Rayjax Dec 04 '12 at 16:53
  • No... but judging by what you said in the description.. you cannot host a web service inside of a Windows Service... WCF can be used both as a Windows Service (if hosted as such) and as a Web Service (if hosted in IIS) – GxG Dec 04 '12 at 17:01
  • SO a windows service can't be reached from remote locations ? I mean, what does ISS have that a windows service doesn't – Rayjax Dec 04 '12 at 17:04
  • A Windows Service _can_ be reached remotely. – John Saunders Dec 04 '12 at 20:57
3

REST / SOAP endpoints for a WCF service

You can expose the service in two different endpoints. the SOAP one can use the binding that support SOAP e.g. basicHttpBinding, the RESTful one can use the webHttpBinding. I assume your REST service will be in JSON, in that case, you need to configure the two endpoints with the following behaviour configuration

<endpointBehaviors>
    <behavior name="jsonBehavior">
        <enableWebScript/>
    </behavior>
</endpointBehaviors>

An example of endpoint configuration in your scenario is

<services>
    <service name="TestService">
        <endpoint address="soap" binding="basicHttpBinding" contract="ITestService"/>
        <endpoint address="json" binding="webHttpBinding"  behaviorConfiguration="jsonBehavior" contract="ITestService"/>
    </service>
</services>

so, the service will be available at
http://www.example.com/soap http://www.example.com/json
Apply [WebGet] to the operation contract to make it RESTful. e.g.

public interface ITestService { [OperationContract] [WebGet] string HelloWorld(string text) }

Note, if the REST service is not in JSON, parameters of the operations can not contain complex type.
For plain old XML as return format, this is an example that would work both for SOAP and XML.

[ServiceContract(Namespace = "http://test")]
public interface ITestService
{
[OperationContract]
[WebGet(UriTemplate = "accounts/{id}")]
Account[] GetAccount(string id);
}

POX behavior for REST Plain Old XML

<behavior name="poxBehavior">
    <webHttp/>
</behavior>

Endpoints

<services>
    <service name="TestService">
        <endpoint address="soap" binding="basicHttpBinding" contract="ITestService"/>
        <endpoint address="xml" binding="webHttpBinding"  behaviorConfiguration="poxBehavior" contract="ITestService"/>
    </service>
</services>

Service will be available at

http://www.example.com/soap http://www.example.com/xml
REST request try it in browser,
http://www.example.com/xml/accounts/A123

SOAP request client endpoint configuration for SOAP service after adding the service reference,

<client>
    <endpoint address="http://www.example.com/soap" binding="basicHttpBinding"
  contract="ITestService" name="BasicHttpBinding_ITestService" />
</client>

in C#

TestServiceClient client = new TestServiceClient();
client.GetAccount("A123");

Another way of doing it is to expose two different service contract and each one with specific configuration. This may generate some duplicates at code level, however at the end of the day, you want to make it working.

Andrea
  • 11,801
  • 17
  • 65
  • 72
Shiva Saurabh
  • 1,281
  • 2
  • 25
  • 47
0

Updated the link to WCF here : http://invalidcast.tumblr.com/post/52980598607/a-gentle-introduction-to-wcf

barneymc
  • 490
  • 1
  • 5
  • 11