मैं निम्न त्रुटि प्राप्त जब मैं एक कस्टम वस्तु
"Object of type 'customObject' cannot be converted to type 'customObject'."
वस्तु टाइप करने के लिए नहीं बदला जा सकता 'customObject'
बाद आह्वान परिदृश्य जब मैं इस त्रुटि मिलती हूँ:
- मैं गतिशील रूप से एक डीएल में एक विधि का आह्वान करता हूं।
- लोड एक विधानसभा
- CreateInstance ....
जब मेरे विधि के लिए एक पैरामीटर के रूप MethodInfo.Invoke() गुजर पूर्णांक, स्ट्रिंग बुला ठीक => कोई अपवाद फेंक दिया जाता है काम करता है।
लेकिन यदि मैं पैरामीटर के रूप में अपनी खुद की कस्टम क्लास ऑब्जेक्ट्स में से किसी एक को कोशिश करता हूं और पास करता हूं, तो मुझे ArgumentException
अपवाद मिलता है, और यह या तो ArgumentOutOfRangeException
या ArgumentNullException
नहीं है।
"Object of type 'customObject' cannot be converted to type 'customObject'."
मैं एक वेब अनुप्रयोग में यह कर रहा हूं।
विधि वाली कक्षा फ़ाइल एक अलग परियोजना में है। साथ ही कस्टम ऑब्जेक्ट एक ही फ़ाइल में एक अलग वर्ग है।
मेरे कोड में static assembly
नामक ऐसी कोई चीज़ नहीं है। मैं गतिशील रूप से एक वेबमाइट का आह्वान करने की कोशिश कर रहा हूं। इस वेबमाइड में कस्टम ऑब्जेक्ट प्रकार इनपुट पैरामीटर के रूप में है। तो जब मैं वेबमाउथ का आह्वान करता हूं तो मैं गतिशील रूप से प्रॉक्सी असेंबली और सभी बना रहा हूं। उसी असेंबली से मैं अपने गुणों के मूल्यों को मानने वाले कुसुम ऑब्जेक्ट का एक उदाहरण बनाने की कोशिश कर रहा हूं और फिर इस ऑब्जेक्ट को पैरामीटर के रूप में पास कर रहा हूं और विधि का आह्वान कर रहा हूं। सब कुछ के बाद किया जाता है एक नमूना कोड मैं इसे
public static object CallWebService(string webServiceAsmxUrl, string serviceName, string methodName, object[] args)
{
System.Net.WebClient client = new System.Net.WebClient();
//-Connect To the web service
using (System.IO.Stream stream = client.OpenRead(webServiceAsmxUrl + "?wsdl"))
{
//--Now read the WSDL file describing a service.
ServiceDescription description = ServiceDescription.Read(stream);
///// LOAD THE DOM /////////
//--Initialize a service description importer.
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.ProtocolName = "Soap12"; // Use SOAP 1.2.
importer.AddServiceDescription(description, null, null);
//--Generate a proxy client. importer.Style = ServiceDescriptionImportStyle.Client;
//--Generate properties to represent primitive values.
importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties;
//--Initialize a Code-DOM tree into which we will import the service.
CodeNamespace nmspace = new CodeNamespace();
CodeCompileUnit unit1 = new CodeCompileUnit();
unit1.Namespaces.Add(nmspace);
//--Import the service into the Code-DOM tree. This creates proxy code
//--that uses the service.
ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit1);
if (warning == 0) //--If zero then we are good to go
{
//--Generate the proxy code
CodeDomProvider provider1 = CodeDomProvider.CreateProvider("CSharp");
//--Compile the assembly proxy with the appropriate references
string[] assemblyReferences = new string[5] { "System.dll", "System.Web.Services.dll", "System.Web.dll", "System.Xml.dll", "System.Data.dll" };
CompilerParameters parms = new CompilerParameters(assemblyReferences);
CompilerResults results = provider1.CompileAssemblyFromDom(parms, unit1);
//-Check For Errors
if (results.Errors.Count > 0)
{
StringBuilder sb = new StringBuilder();
foreach (CompilerError oops in results.Errors)
{
sb.AppendLine("========Compiler error============");
sb.AppendLine(oops.ErrorText);
}
throw new System.ApplicationException("Compile Error Occured calling webservice. " + sb.ToString());
}
//--Finally, Invoke the web service method
Type foundType = null;
Type[] types = results.CompiledAssembly.GetTypes();
foreach (Type type in types)
{
if (type.BaseType == typeof(System.Web.Services.Protocols.SoapHttpClientProtocol))
{
Console.WriteLine(type.ToString());
foundType = type;
}
}
object wsvcClass = results.CompiledAssembly.CreateInstance(foundType.ToString());
MethodInfo mi = wsvcClass.GetType().GetMethod(methodName);
return mi.Invoke(wsvcClass, args);
}
else
{
return null;
}
}
}
बनाने की कोशिश की है कि मैं क्या में कुछ भी static
नहीं मिल सकता है गतिशील है और कुछ भी नहीं स्थिर बनाई गई है .. :(
ऐड संदर्भ नहीं किया जाता है। मैं है।
किसी भी मदद की बहुत सराहना कर रहा है।
सादर, फणी कुमार पीवी
* आप यह क्यों करेंगे? क्यों न सिर्फ परियोजना में "वेब संदर्भ जोड़ें"? – Aaronaught
मैं एक ऐप विकसित कर रहा हूं जिसमें डब्ल्यूएसडीएल यूआरएल दिया गया है, मुझे इसमें एक वेबमाउथ लगाने की आवश्यकता है। क्योंकि मुझे विभिन्न वेबमाइड्स का उपयोग करना है, मैं एक वेब संदर्भ नहीं कर सकता। –