0

I have a WCF REST service that needs to communicate with another WCF REST service.

There are three websites:

  • Default Web Site
  • Website1
  • Website2

If I set up both services in Default Web Site and connect to the other (using HttpClient) using the URI http://localhost/service then everything is okay.

The desired set-up is to move these two services to separate websites and rather than using the URI http://localhost/service, accessing the service via http://website1.domain.com/service still using HttpClient.

I received the exception:

System.ArgumentOutOfRangeException: Unauthorized (401) is not one of the following: OK (200), Created (201), Accepted (202), NonAuthoritativeInformation (203), NoContent (204), ResetContent (205), PartialContent (206)

I can see this is a 401, but what is going on here?

Thanks

skaffman
  • 398,947
  • 96
  • 818
  • 769
youwhut
  • 948
  • 3
  • 17
  • 37
  • 1
    If you could add your HttpClient code (configuration/execution) it would be most useful in helping you figure out the problem. – Drew Marsh Apr 15 '12 at 18:15

3 Answers3

0

I think this is related to your setup for webservice. It is best if you just create GET,POST,Put,DELETE heartbeat calls for new services and then check those from fiddler. If you get 401, it may mean your app pool identity could not access something.

Steps to fix that:

  1. Give user read/write/modify/execute/..similar rights at your WCF publish folder
  2. Create app pool for this site in .net 4 integrated
  3. Set this user to application pool identity, enable anonymous mode
  4. Enable PUt,Delete verbs as well

Part of a heartbeat class in your service to test calls:

  [DataContract]
public class StatusInfo
{
    [DataMember]
    public string MachineName { get; set; }

    [DataMember]
    public string IpAddress{ get; set; }

    [DataMember]
    public string Methodname { get; set; }

    public override string ToString()
    {
        return "Machinename:" + MachineName + " ;IP:" + IpAddress + "; Method:" + Methodname;
    }
}

private void ResolveStatus(StatusInfo statusInfo,string methodname)
    {
        try
        {
            var context = System.ServiceModel.OperationContext.Current;

            RemoteEndpointMessageProperty property =
                (RemoteEndpointMessageProperty)
                context.IncomingMessageProperties[RemoteEndpointMessageProperty.Name];


            statusInfo.IpAddress = property.Address;
            statusInfo.MachineName = Environment.MachineName;
            statusInfo.Methodname = methodname;

        }catch(Exception ex)
        {

        }
    }
/// <summary>
    /// create task
    /// </summary>
    /// <param name="taskwrapped"></param>
    [WebInvoke(Method = "POST", UriTemplate = "", RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    public StatusInfo postcall()
    {
        StatusInfo statusInfo = new StatusInfo();
        logger.Trace(Tagname + "postcall");
        ResolveStatus(statusInfo, "POST");
        return statusInfo;

    }


    /// <summary>
    /// edit task
    /// </summary>
    [WebInvoke(Method = "PUT", UriTemplate = "", RequestFormat = WebMessageFormat.Json,
              ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    public StatusInfo Edit()
    {
        StatusInfo statusInfo = new StatusInfo();
        logger.Trace(Tagname + "Edit");
        ResolveStatus(statusInfo, "PUT");
        return statusInfo;

    }

    //delete request with taskid
    [WebInvoke(Method = "DELETE", UriTemplate = "", RequestFormat = WebMessageFormat.Json,
     ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    public StatusInfo DeleteCall()
    {
        StatusInfo statusInfo = new StatusInfo();
        logger.Trace(Tagname + "Edit");
        ResolveStatus(statusInfo, "DELETE");
        return statusInfo;

    }


    //delete request with taskid
    [WebInvoke(Method = "DELETE", UriTemplate = "/{recordid}", RequestFormat = WebMessageFormat.Json,
     ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    public StatusInfo DeleteCallWithParam(string recordid)

    {
        StatusInfo statusInfo = new StatusInfo();
        logger.Trace(Tagname + "Edit");
        ResolveStatus(statusInfo, "DELETE/"+recordid);
        return statusInfo;

    }



enter code here
Omer Cansizoglu
  • 1,271
  • 9
  • 14
0

I received the exception:

Who is "I"? One of the web services or some other client?

If I'm understanding things correctly, it's the receiving end that seems to be expecting a range of responses, 401 not being one of them. It maybe some error checking code that expects "this range" of responses and does X (and 401 isn't one of these, or there is no "default" method to account for x response?).

That said, 401, is an authorization error so check on possible ServiceAuthorizationManager and/or similar settings in place that isn't being met by "I" causing the 401 response in the first place....

Hth...

EdSF
  • 11,753
  • 6
  • 42
  • 83
0

My guess is you are missing authorizaton headers or credentials.

Check this out :

Community
  • 1
  • 1
JoeBilly
  • 3,057
  • 29
  • 35