In simple form, I wrote a console application that (among many other things) makes two SOAP calls to different Web Services. It was a stand-alone solution, so I just put the two WSDL files in as Service References and created wrapper classes to invoke them and return data. I created two Service References, GetSession
, and SubscriptionNotifications
in the project and wrote two wrapper classes to instantiate the soap clients, initialize them, call them, and return data. Code is proprietary, so I can only show snippets.
Solution Explorer shows basically:
Solution 'MySolution'
MySolution
Properties
References
ServiceReferences (folder)
GetSession
SubscriptionNotifications
Code (folder for .cs files)
Program.cs
EmailUtil.cs
DataRepository.cs
SOAP_GetSession.cs
SOAP_SendSubscriptionNotifications.cs
App.config
packages.config
In SOAP_GetSession.cs (partial code) I wrote
using MyNamespace.GetSession; // the autogenerated SOAP client
namespace MyNamespace.MySolution.Code
{
class SOAP_GetSession {
public static string GetAppToken() {
string env = configFile.GetConfigValue("Environment");
string userName = configFile.GetConfigValue("UserName");
string password = configFile.GetConfigValue("Password");
string appId = configFile.GetConfigValue("ApplicationId");
string appToken = "";
try {
ServiceClient sc = new ServiceClient();
SessionResponse sr = sc.GetSession(env, userName, password, appId);
appToken = sr.ApplicationSession;
}
catch (...) {
// do exception handling
}
return appToken;
}
}
}
I skipped most of the inessential code in the class, but this is the essence and it works fine. Now, I want to take the two SOAP calls and create separate projects as Class Libraries within the solution and move the SOAP functionality to these projects so the projects can be used intact in other solutions. I have been having endless referential and namespace problems all day. Even though the projects are meant to be stand-alone with no dependencies and each has its own ServiceReference WSDL client, I can't get the right combination of "using"s, references, namespaces, and dependencies to get either program to recognize its SOAP client's objects and methods in my own code. Everything I try brings up errors that the ServiceClient or the GetSession()
or ServiceResponse
reference can not be found in the namespace. I've qualified them with namespaces, inserted using statements, and everything else I can think of to no avail.
Can anybody sketch out a simple class and method like the one I showed above that will work in its own project and can be referenced by the main startup project?