开发者

JSON and WCF Web service

开发者 https://www.devze.com 2023-03-08 00:21 出处:网络
First off, this is my first post on stack overflow. I have been visiting this site for a long time and have never really asked a question because of the abundant resources already available. One probl

First off, this is my first post on stack overflow. I have been visiting this site for a long time and have never really asked a question because of the abundant resources already available. One problem I am having seems to be a little difficult to find correct information on. If my post is not appropriate or there is anything I should consider in the future before posting ple开发者_StackOverflow中文版ase let me know.

I am working on a WCF interface for a somewhat simple windows service. The idea is that it will have two endpoints available, a TCP endpoint and an HTTP endpoint using JSON.

I have the WCF interface complete so I can test it by navigating to the proper URL, and everything seems great. The next step which is a little difficult for me is the java client side of things. I need to create a java class to interface with the WCF service. I could use a URLConnection to invoke a GET, but how would I go about this with a POST? Below is an example of the service contract.

[ServiceContract]
public interface IPenguinWCF_JSON
{
    [OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "listsigns/")]
    string[] ListSigns();

    [OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "stopserver/")]
    bool StopServer();

    [OperationContract]
    [WebInvoke(Method = "POST",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "sendmessage")]
    bool SendMessage(string signName, string zone, string text, bool scroll);


You can use the Apache HttpClient library to write a client.

0

精彩评论

暂无评论...
验证码 换一张
取 消