private Assembly BuildAssemblyFromWSDL(Uri webServiceUri)
{
if (String.IsNullOrEmpty(webServiceUri.ToString()))
throw new Exception("Web Service Not Found");
//This following code does not work for NAV Web services so I replaced it
//XmlTextReader xmlreader = new XmlTextReader(webServiceUri.ToString() + "?wsdl");
// Start of new code -->
l_http = (HttpWebRequest)WebRequest.Create(webServiceUri.ToString());
_Credntial = new System.Net.NetworkCredential("Username", "password","Domain");
l_http.Timeout = 50000; // Timeout after 5 seconds
l_http.UseDefaultCredentials = false;
l_http.PreAuthenticate = true;
l_http.Credentials = _Credntial;
l_http.PreAuthenticate = true;
//l_http.GetResponse(
//l_http.UseDefaultCredentials = false;
//_Credntial = System.Net.CredentialCache.DefaultCredentials;
//PropertyInfo UseDefaultCred =
HttpWebResponse l_response = (HttpWebResponse)l_http.GetResponse();
Encoding enc = Encoding.GetEncoding(1252); // Windows default Code Page
StreamReader l_responseStream = new StreamReader(l_response.GetResponseStream(), enc);
XmlTextReader xmlreader = new XmlTextReader(l_responseStream);
// End of new code <--
ServiceDescriptionImporter descriptionImporter = BuildServiceDescriptionImporter(xmlreader);
return CompileAssembly(descriptionImporter);
}
public T InvokeMethod<T>( string serviceName, string methodName, params object[] args )
{
// create an instance of the specified service
// and invoke the method
Object obj = this.webServiceAssembly.CreateInstance(serviceName);
Type t1 = l_http.GetType();
Type type = obj.GetType();
// NAV Web services failed here because the service was not using default credentials
// Start of inserted code --->
// Try to tell it to useDefaultCredentials.
PropertyInfo UseDefaultCred = type.GetProperty("UseDefaultCredentials");
//PropertyInfo UseDefaultCred =
UseDefaultCred.SetValue(obj, true,null);
// End of inserted code <---
return (T)type.InvokeMember(methodName,BindingFlags.InvokeMethod,null, obj,args);
}
Answers
http://blogs.msdn.com/freddyk/archive/tags/Dynamic/default.aspx
If your code works locally and NOT from a different machine, then there shouldn't be anything wrong with your code though.
Are the machines are not in the same domain, then you cannot use default credentials.
If they are in the same domain - then the problem might be delegation, spn's etc. - can you start the RTC on that machine?
Group Program Manager, Client
Microsoft Dynamics NAV
http://blogs.msdn.com/freddyk
The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
Thanks fro the quick response.
your blog is full of webservice examples and it helps me solve the problem.
=D> =D> =D>
Thanks once again
Rajesh Patel
Can you tell the exact reason of this error and how did you solved it????
Ahmedabad, Gujarat, India
E Mail : ravi.thakkar@hotmail.com