Search code examples
wcfoperationcontractoperationcontextweboperationcontext

WCF - Calling WebGet Request From Another Service


There is a web service I am integrating into. Service asks for an url parameter for redirection after it does its' thing.

I have created a WebGet request like: myserviceUrl/redirect/someVal/someOtherVal and gave the url to the request as parameter.

Now, when I enter the url into browser (running from VS as localhost), I can confirm that it is working as I intended. But when the address I give as parameter is called from the web service, browser shows a page that says

Service - Method not allowed.

If I click on address bar and hit enter (with the url which seems to be correct) it works.

What could be the source of this problem, is it a domain, authentication thing? How can I work around this. Is there a web.config setting I can change or some request attribute I should be tinkering with?

I searched the web quite a bit but can't seem to find a solution that works.

Edit: (based on oshvartz's comment)

It's a DLL I am calling from my service initialization for testing purposes.

public static void AppInitialize()
{
    ServicePostContent con = new ServicePostContent()
    {
        param1 = "val",
        param2 = "val2",
        responseUrl = "myserviceUrl/redirect/someVal/someOtherVal"
    }
    PostResponse res = Service.PostData(con);
}

IService1.cs:

[WebGet (UriTemplate = "redirect/{someVal}/{someOtherVal}")]
[OperationContract] void Test(string someVal, string someOtherVal);

Service1.svc:

public void Test(string someVal, string someOtherVal)
{
     System.Diagnostics.Debug.WriteLine(someVal + " / " + someOtherVal);
}

Solution

  • From your error, it seems the method you call your rest service is not suitable. Your service is WebGet, and from your code ServicePostContent, it seems you are using a post method to call the rest service.

    Dose your ServicePostContent use get method to call the rest service?

    Or you could change your Webget to WebInvoke and set the Method property to POST

     [WebInvoke(UriTemplate = "redirect/{someVal}/{someOtherVal}", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
        [OperationContract] void Test(string someVal, string someOtherVal);