开发者

HTTP POST to a WCF service

What needs to happen to allow an HTTP POST to a WCF service?

I would like to allow people to not only use SOAP with this service, but they must also be able to HTTP POST to this service and ideally receive an XML response.

I cannot find an easy way to allow a 开发者_JS百科WCF service to accept an HTTP POST.

I am past the HTTP 415 error and need some help with maybe a web.config change regarding endpoints, or an additional attribute above the method (WebInvoke).

Thank you!


In order to talk to a WCF service over the standard HTTP verbs, you need to use the WCF REST components.

In .NET 3.5 SP1, there's the WCF REST Starter Kit that you'll need (it's not part of the basic package).

When you have this, you can define an endpoint in your WCF service with a webHttpBinding and that basically should allow you to define GET, POST, PUT and DELETE operations.

Check out the WCF REST developer center for a great deal of white papers, tutorials, walk throughs and screencasts showing you exactly how to do all of this.

In a nutshell, you would adorn your service method(s) that you want to expose over HTTP REST with WebGet or WebInvoke attributes and a URL template - something like:

[ServiceContract]
public partial class YourService
{
    [WebInvoke(Method = "POST", UriTemplate = "yourservice/{id}/save")]
    [OperationContract]
    SomeReturnType YourMethodCall(string someParam);
    ...
}

and then, in your web.config (for hosting in IIS) or in app.config you need an endpoint with the right binding:

<endpoint name="webEndpoint"
          address="...."
          binding="webHttpBinding"
          contract="IYourServiceContract" />

You might also need a few extra things in your config - the WCF REST dev center should go into all the details in great depth.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜