locked
CRM 4.0: Problem with "Using CrmService" RRS feed

  • Question

  • I am trying to implement the Routes portion from this website (http://sundium.wordpress.com/2008/06/15/dynamics-crm-40-virtual-earth ). While I have had success with other work in CRM using the API for Virtual Earth, I have not yet used the CrmService to pull data that doesn't already exist on the page.

    I have been trying to get CrmService to work but keep getting this error:

    Compiler Error Message: CS0246: The type or namespace name 'CrmService' could not be found (are you missing a using directive or an assembly reference?)

    Source Error:

     
    Line 9:  using System.Web.UI.WebControls;
    Line 10: using System.Web.UI.WebControls.WebParts;
    Line 11: using CrmService;
    Line 12:
    Line 13: public partial class Routes : System.Web.UI.Page

    Source File: c:\Inetpub\wwwroot\crmMap\Routes.aspx.cs    Line: 11


    The pertinent code from the CS file is below. I have tried to recreate the project adding variations on the web reference name, verifying that the PC developing the project can see the web services. What am I missing?

    Also, I didn't want to double post, so if this is more appropriate in development, could a moderator please move it?

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using CrmService;

    public partial class Routes : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Read the Service Activity ID from query string
            String saId = this.Request.QueryString["id"];
           
            if (!String.IsNullOrEmpty(saId))
            {
                // Retrieve contact instance from CRM
                Guid contactId = new Guid(saId);

                CrmAuthenticationToken token = new CrmAuthenticationToken();
                token.OrganizationName = "MicrosoftCRM";
                CrmService.CrmService crmService = new CrmService.CrmService();
                crmService.CrmAuthenticationTokenValue = token;
                crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
                contact apmt = crmService.Retrieve("contact", contactId, new AllColumns()) as CrmService.contact;
    Saturday, May 16, 2009 7:23 PM

Answers

  • add this line of javascript code to the onload event of one of your CRM forms:

    alert("ORG_UNIQUE_NAME="+ORG_UNIQUE_NAME);

    What shows up in the popup box needs to go in the token.OrganizationName line:

    token.OrganizationName = "the case sensitive unique org name";
    Wednesday, May 20, 2009 7:52 PM

All replies

  • Hi there,

    The error is saying that it cannot find the reference 'CrmService'.

    Please add the CrmService to the solution project - http://msdn.microsoft.com/en-us/library/cc151015.aspx
    http://mscrmblog.net - sys admin
    Sunday, May 17, 2009 8:51 AM
  • That I know. I rebuilt the solution from scratch. I can run the CS file from the PC used for development, but when I move the folder structure over to the CRM server, it gives me that same error. Do I have to modify anything because I am moving it?
    Monday, May 18, 2009 12:05 PM
  • If I'm understanding you correctly.

    Find the correct web service URL that's accessible from WITHIN the server. To find out - point your web browser ON THE SERVER, to what's set in the web.config, see if you are NOT able to see the service definition, change it the the service url.

     <appSettings>
      <add key="CrmService.CrmServiceWsdl" value="http://moss:5555/MSCrmServices/2007/CrmService.asmx"/>
     </appSettings>


    Could be the host wasn't resolved within the server, so should be refering to http://LOCALHOST:5555/MSCrmServices/2007/CrmService.asmx instead of http://moss:5555/MSCrmServices/2007/CrmService.asmx, something along that line?

    Let us know how you get on mate.

    Sun - MSCRM Specialist @ Intergen, Sunny (slightly breezy)Wellington, New Zealand. http://sundium.wordpress.com
    Tuesday, May 19, 2009 12:47 PM
  • Hi,

    First, did you create a web reference for the CRM web service? In my case I created a folder called CRMWEBSERVICE and I added the CRSDKService with the .discomap and .wsdl file.

    Second, Sun from New Zealand is correct. You have to create a service url. In my case it is like this:

    <appSettings>
    		<add key="ReportingService.ReportService" value="http://crm/ReportServer/ReportService.asmx"/>
    	<add key="CrmWebService.CrmSDKService.CrmServiceWsdl" value="http://crm/MSCrmServices/2006/CrmService.asmx"/>
    	</appSettings>
    Once you are sure you have all this, just use the namespace:

    using

     

    CrmWebService.CrmSDKService;

    Let us know.


    Eduardo
    Tuesday, May 19, 2009 3:08 PM
  • The asmx url resolves to this page: http://server-crm/MSCrmServices/2007/CrmServiceWsdl.aspx and displays the xml wdsl definitions detail. I'm sure that I am missing something simple, I just don't know what it is.

    Here are my web.config lines:

        <applicationSettings>
            <crmMapLive.Properties.Settings>
                <setting name="crmMapLive_CrmService_CrmService" serializeAs="String">
                    <value>http://server-crm/MSCrmServices/2007/CrmService.asmx</value>
                </setting>
            </crmMapLive.Properties.Settings>
        </applicationSettings>
    

    Here is the folder structure:

    Tuesday, May 19, 2009 4:29 PM
  • Update:

    I recreated again being very careful about locations, naming, etc. It runs in the debugging server from VS2005. When I move it to the server (Win2003,IIS6) it chokes on the authentication piece:
    Line 26:             ASP.NET to identify an incoming user. 
    
    Line 27:         -->
    
    Line 28: 		 <authentication mode="Windows"/> 
    
    Line 29: 		<!--
    
    Line 30:             The <customErrors> section enables configuration
    Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS.


    I have verified that this is a virtual directory and has permission to run ASP scripts. If I try to remove the auth piece, I get the CrmService error previously, if the auth piece is in (set to Windows or None) it errors as directly above.
    Tuesday, May 19, 2009 7:59 PM
  • Can ou post your webconfig file? Let me take a look at it.
    Eduardo
    Tuesday, May 19, 2009 9:46 PM
  • I made some changes to the structure and now have moved the folder up the tree. That seemed to have addressed the previous issues, but now when it is mid-process I get an unhandled exception. I am not sure whether I should be commenting out the auth mode or not...

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

    Source Error:

    Line 291:        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://schemas.microsoft.com/crm/2007/WebServices/Retrieve", 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 292: public BusinessEntity Retrieve(string entityName, System.Guid id, ColumnSetBase columnSet) {
    Line 293: object[] results = this.Invoke("Retrieve", new object[] {
    Line 294: entityName,
    Line 295: id,

    Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\crmmaplive\60b58791\ac27e833\App_WebReferences.guo3-twy.0.cs    Line: 293

    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) +551137
    System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +204
    CrmSdk.CrmService.Retrieve(String entityName, Guid id, ColumnSetBase columnSet) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\crmmaplive\60b58791\ac27e833\App_WebReferences.guo3-twy.0.cs:293
    Routes.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\crmMap\crmMapLive\Routes.aspx.cs:30
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
    System.Web.UI.Control.OnLoad(EventArgs e) +99
    System.Web.UI.Control.LoadRecursive() +47
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
     

    Here is the web.config:

    <?xml version="1.0"?>
    <!-- 
        Note: As an alternative to hand editing this file you can use the 
        web admin tool to configure settings for your application. Use
        the Website->Asp.Net Configuration option in Visual Studio.
        A full list of settings and comments can be found in 
        machine.config.comments usually located in 
        \Windows\Microsoft.Net\Framework\v2.x\Config 
    -->
    <configuration>
    	<appSettings>
    		<add key="CrmSdk.CrmServiceWsdl" value="http://server-crm/MSCrmServices/2007/CrmService.asmx"/>
    	</appSettings>
    	<connectionStrings/>
    	<system.web>
    		<!-- 
                Set compilation debug="true" to insert debugging 
                symbols into the compiled page. Because this 
                affects performance, set this value to true only 
                during development.
            -->
    		<compilation debug="true"/>
    		<!--
                The <authentication> section enables configuration 
                of the security authentication mode used by 
                ASP.NET to identify an incoming user. 
            -->
    		 <!-- <authentication mode="windows"/> -->
    		<!--
                The <customErrors> section enables configuration 
                of what to do if/when an unhandled error occurs 
                during the execution of a request. Specifically, 
                it enables developers to configure html error pages 
                to be displayed in place of a error stack trace.
    
            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
            -->
    	</system.web>
    </configuration>
    
    Wednesday, May 20, 2009 3:18 AM
  • For what it's worth... I turned the auth back to windows and changed IIS to basic auth. When prompted for my credentials, I used my domain logon info...took the info and returned the same 401 not authorized error. When I use a local username/password, I get the error that no user with that domain/username exist in CRM.
    Wednesday, May 20, 2009 4:08 PM
  • It appears you have not created the web site in iis all the way. 

    In iis, right click your virtual folder and choose properties
    In the Application Settings section on the Virtual Directory tab, click the Create button
    Assign an app pool which uses asp.net 2.0 and don't forget to set the ASP.Net to 2.0 on the ASP.Net tab.

    Also, on the Directory Security tab, in the Anonymous access and authentication control section, click Edit
    Make sure that Anonymous access is unchecked and Integrated Windows authentication is checked.

    Also, in response to your original post, try adding the root namespace in your using statement, like this:

    using crmMapLive.CrmService;
    Wednesday, May 20, 2009 5:22 PM
  • Thanks for the responses. Hereis the current status:

    When I check the iframe property in CRM, "Pass record object-type code and unique id as params", I get the error two posts above. When I have it unchecked, the map shows in the iframe, but I don't get the address values to populate the variables for directions.


    Wednesday, May 20, 2009 6:37 PM
  • add this line of javascript code to the onload event of one of your CRM forms:

    alert("ORG_UNIQUE_NAME="+ORG_UNIQUE_NAME);

    What shows up in the popup box needs to go in the token.OrganizationName line:

    token.OrganizationName = "the case sensitive unique org name";
    Wednesday, May 20, 2009 7:52 PM
  • ding-ding-ding...We've got a winner!

    thanks so much!
    Wednesday, May 20, 2009 8:07 PM