locked
CRM Case Creation ..newbie...throwing http:401 unauthorized error..plz help RRS feed

  • Question

  • Hi, i am trying to create a crm case and its throwing me an http:401 unauthorizwed error.

    The userid has access to the crm server. He is able to access the crm website.

    Plzz help me fix this.

     using System;

    using System.Data;

    using System.Configuration;

    using System.Collections;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    using System.Web.Services.Protocols;

    using System.Xml;

    using System.Security.Principal;

    using CrmSdk;

    public partial class newcase: System.Web.UI.Page

    {

    protected void Page_Load(object sender, EventArgs e)

    {}

     

    protected void btnSubmit_Click(object sender, EventArgs e)

    {

    string UserID = System.Configuration.ConfigurationSettings.AppSettings["UserID"];

    string Password = System.Configuration.ConfigurationSettings.AppSettings["Password"];

    string Domain = System.Configuration.ConfigurationSettings.AppSettings["Domain"];

     

     

    CrmAuthenticationToken token = new CrmAuthenticationToken();

    token.OrganizationName = "AzoxInc";

    token.AuthenticationType = 0;

    //set up the CRM Service

    CrmService service = new CrmService();

    service.Url = System.Configuration.ConfigurationSettings.AppSettings["CrmSdk.CrmServiceWsdl"];

    service.CrmAuthenticationTokenValue = token;

    //service.UseDefaultCredentials = true;

    service.Credentials = new System.Net.NetworkCredential( UserID, Password, Domain);

    Response.Write("hello");

    // Create Case Object

    incident myIncident = new incident();

    // Assign TITLE

    myIncident.title = TextBox1_CaseTitle.Text;

    // Assign Description

    myIncident.description = TextBox3_CaseDescription.Text;

    // Assign Contact / Account

    Customer objAccount = new Customer();

    objAccount.type = EntityName.account.ToString(); // For Contact use : EntityName.contact.ToString();

    objAccount.Value = new Guid("{FC0B543B-AEBF-DD11-8B0C-003048972369}"); // For Contact specify contact Guid DIBA SHOES

    myIncident.customerid = objAccount;

    Lookup subjectLookup = new Lookup();

    subjectLookup.type = EntityName.subject.ToString();

    subjectLookup.Value = new Guid("{1331FA50-5AFE-DF11-93C7-00155D04E54B}"); // specify your Subject Guid

    myIncident.subjectid = subjectLookup;

    // Assign OWNER

    Owner ownerObject = new Owner();

    ownerObject.Value = new Guid("{2BA1E169-6101-E011-93C7-00155D04E54B}"); // Specify your user guid

    ownerObject.type = EntityName.systemuser.ToString();

    myIncident.ownerid = ownerObject;

    // Assign Case Status

    myIncident.statecode = new IncidentStateInfo();

    myIncident.statecode.Value = IncidentState.Active;

    // Create CASE/Incident

    Guid IncidentGuid = Guid.Empty;

    // try

    // {

    // //Response.Write("hello");

    IncidentGuid = service.Create(myIncident);

    // }

    // catch (System.Web.Services.Protocols.SoapException ex)

    // {

    // // throw ex;

    //Response.Write(ex.Message);

    // }

    // catch (Exception ex)

    // {

    // //throw ex;

    // Response.Write(ex.Message);

    // }

    Response.Write("test");

    }

    }

     

     

     

     

    This is the error that shows up.. pl help

     

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Net.WebException: The request failed with HTTP status 401: Unauthorized.

    Source Error:

     

    Server Error in '/Deployment/OnlineSupportPN/ecom/eSource' Application.

    The request failed with HTTP status 401: Unauthorized.

     

     

     

    Line 202:  [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://schemas.microsoft.com/crm/2007/WebServices/Create", RequestNamespace="http://schemas.microsoft.com/crm/2007/WebServices", ResponseNamespace="http://schemas.microsoft.com/crm/2007/WebServices", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    
    Line 203:  public System.Guid Create(BusinessEntity entity) {
    
    Line 204:   object[] results = this.Invoke("Create", new object[] {
    
    Line 205:      entity});
    
    Line 206:   return ((System.Guid)(results[0]));

    Source File: c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\deployment_onlinesupportpn_ecom_esource\c5682095\f29fbc4\App_WebReferences.sa_nmkag.0.cs    Line: 204

    Stack Trace:

    [WebException: The request failed with HTTP status 401: Unauthorized.]
    
     System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +431237
    
     System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +204
    
     CrmSdk.CrmService.Create(BusinessEntity entity) in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\deployment_onlinesupportpn_ecom_esource\c5682095\f29fbc4\App_WebReferences.sa_nmkag.0.cs:204
    
     ecom_eSource_sample_newcase.btnSubmit_Click(Object sender, EventArgs e) in d:\inetpub\wwwroot\Deployment\OnlineSupportPN\ecom\eSource\sample\newcase.aspx.cs:139
    
     System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
    
     System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
    
     System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    
     System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    
     System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
    
    

     


    Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4955

    Tuesday, December 7, 2010 10:39 PM

Answers

All replies