It should be possible (and it looks like it is), but assume I have the following functions in my ASMX web service:
[WebMethod(MessageName = "CreateExternalRpt1")]
public bool CreateExternalRpt(int iProductId, int iOrderProductId, DateTime dtReportTime, string strReportTitle,
string strReportCategory, string strReportPrintType, out string strSnapshot, string strApplicantFirst, string strApplicantLast,
string strApplicantMiddle, string strOwnerLast, string strOwnerMiddle, string strOwnerFirst,
bool blnCurrentReport, int iOrderId, bool blnFlag, string strCustomerId, string strUserId)
{
…
}
[WebMethod(MessageName = "CreateExternalRpt2")]
public bool CreateExternalRpt(int iProductId, int iOrderProductId, DateTime dtReportTime, string strReportTitle,
string strReportCategory, string strReportPrintType, string strReportSnapshot, string strApplicantFirst, string strApplicantLast,
string strApplicantMiddle, string strOwnerLast, string strOwnerMiddle, string strOwnerFirst,
bool blnCurrentReport, int iOrderId, bool blnFlag)
{
…
}
With both of these functions defined in my web service, my .NET client app can’t download the metadata and instead throws a generic error message “There was an error downloading…”.
With one of the above methods removed, the .NET client app can successfully download the metadata.
I’ve read that by decorating the WebMethod with a unique name, both functions should be exposed in the service metadata.
This isn’t working. What am I missing?
:) - I'm sure once you think about it a minute or two, you'll realize.
Keep in mind that when you're making a traditional call using SOAP, you know a method at the time of the call but don't know the entire signature. You may expect that it contains params A, B, and C, but you're not 100% sure.
As another poster mentioned... Can web methods be overloaded?
There are several ways to overload methods in ASMX by using message-based routers. However, I've never gone that route and have heard many having issues doing so. I'd recommend WCF for overloads. http://jeffbarnes.net/blog/post/2006/09/21/overloading-methods-in-wcf.aspx
Related
I recently saw code like:
public String myMethodHere(#RequestParam(PARAM_FOO_ID) Integer fooId,
Model model) {
//some implementation
}
private static final String PARAM_FOO_ID = "fooId";
Is there a benefit in making a request param a static final String?
I didn't see it referenced anywhere else on SO and the examples in the Spring docs don't do this.
There is not benefit in terms of performance as strings are interned anyway. But this way, it is more maintainable.
If you have several controller methods that accepts "fooId" as request parameter, you can just reuse PARAM_FOO_ID in all those controllers. Then if the client side decides to change the request parameter to send to your rest endpoint, all it takes is just a change to the value of PARAM_FOO_ID then your controller is ready to accommodate those changes.
I need a way to fake DateTime.Parse with Typemock and have it return the same date when called with any parameters.
I have a DB field that stores an encrypted string that is parsed as date when loaded. The class that holds the data has a Load() method where it copies DB data into its properties, decrypts what's encrypted and does some basic validation, such as:
public class BusinessObject{
public DateTime ImportantDate{get;set;}
...
public void Load(DBObject dbSource){
...
ImportantDate = DateTime.Parse(DecryptionService.Decrypt(dbSource.ImportantDate));
}
}
Runtime all works well.
I'm trying to write a unit test using TypeMock to load some fake data into BusinessObject using its Load method. BusinessObject has way too many properties and can not be deserialized from XML, but DBObject can, so I've stored some XMLs that represent valid data.
It all works well until DecryptionService is called to decrypt the data - it doesn't work because my dev machine doesn't have the DB certificates used in the encryption process. I can't get those on my machine just for testing, that would be a security breach.
I added this to my unit test:
Isolate.Fake.StaticMethods<DecryptionService>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => DecryptionService .Decrypt(null)).WillReturn("***");
Isolate.Fake.StaticMethods<DateTime>(Members.ReturnNulls);
Isolate.WhenCalled(() => DateTime.Parse("***" /*DateStr*/)).WillReturn(DateTime.Now.AddYears(2));
The first part where DecryptionService is faked works, social security and other sensitive strings are "decrypting", but no matter what parameters I give to DateTime I still get one exception or another (ArgumentNullException: String reference not set to an instance of an object if DateStr is null, FormatException when it's "*")
How (if) can I override DateTime.Parse with typemock so that it returns valid DateTime with any invalid paramters passed?
My name is Nofar and i'm from Typemock's support team.
DateTime.Parse is not supported in the WhenCalled API, so in order to fake it's returned value you need to wrap it with a method from your class, for example:
public class BusinessObject
{
public DateTime Load (string s)
{
return DateTime.Parse(s);
}
}
And you test will look like this:
[TestMethod]
public void TestMethodDateTime()
{
BusinessObject b = new BusinessObject();
DateTime now= DateTime.Now.AddYears(2);
Isolate.WhenCalled(()=>b.Load(null)).WillReturn(now);
Assert.AreEqual(now, b.Load(null));
}
Supporting DateTime.Parse in the WhenCalled API is in our backlog.
Please feel free to contact us via mail at support#typemock.com
Nofar
Typemock Support
Ok, so I can't seem to find decent Windows Azure examples. I have a simple hello world application that's based on this tutorial. I want to have custom output instead of JSON or XML. So I created my interface like:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(UriTemplate = "session/create", Method = "POST")]
string createSession();
}
public class MyService : IService
{
public string createSession()
{
// get access to POST data here: user, pass
string sessionid = Session.Create(user, pass);
return "sessionid=" + sessionid;
}
}
For the life of me, I can't seem to figure out how to access the POST data. Please help. Thanks!
If you have an HttpContext there may be a Request object that would have the form data. I'm basing part of this off the ASP.Net tag on this question, so if that is incorrect then there may be the need to handle this another way but it looks a lot like a web service to my mind.
EDIT: HttpRequest is the class that has the Form property that should be where the POST data is stored if this is an HTTP request. This is part of System.Web so it should be ready to be used pretty easily, as I recall.
Sample code showing the Request.Form property:
int loop1;
NameValueCollection coll;
//Load Form variables into NameValueCollection variable.
coll=Request.Form;
// Get names of all forms into a string array.
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
Response.Write("Form: " + arr1[loop1] + "<br>");
}
This presumed there was an HttpRequest instance around.
WCF Simplified Part 4: Comparing the Request/Reply and One-Way Patterns passes in a parameter so that your "createSession" method would have to take in those strings it would appear. I'm used to the ASP.Net world where there are some built-in objects like Request, Response, Server, Application and Session.
Yes, if you did try changing the method signature as there are ways to pass in parameters in that last example I linked though I don't know if that would work in your case or not.
I'm wondering whether it's possible to use built in ASP.NET application services (aspnet_user, aspnet_role etc table) without specifying a connection string in a web.config.
At the moment I store connection strings externally, but I keep finding hard-coded connection strings all over the web.config xml, various providers etc. It's driving me crazy.
Thank you
You can write your own provider via overriding already existed, built-in class so it will read it's connection string from somewhere else:
public class MyMembershiProvider : SqlMembershiProvider
{
public override void Initialize(string name, NameValueCollection config)
{
config["connectionString"] = "what ever you want";
base.Initialize(name, config);
}
}
I have an MVC web app that uses a custom folder & namespace for resource files. I need to be able to pull late-bound values from my resource file, i.e. using the resource type and string. I tried using:
HttpContext.GetGlobalResourceObject("ResourceClass", "SomeKey")
But that returns null. When I move the resource to App_GlobalResources, that works, but cascades into other issues. I tried working through those, but they seem to be deeper and more in number than going back to my original plan of just being able to read from the resource file in the custom folder.
In a nutshell, I'm trying to localize my xVal validation, both the error message, and in the case of a RegEx validator, the pattern. I've got everything working, except for this one piece, where I'm trying to localize the pattern. Since this isn't built into DataAnnotations.RegularExpressionAttribute, I need to fetch it myself, based on the resource type and name provided in the attribute. Hence my dilemma.
Can I get to the resource value using some other method? Or, must my resource file reside in the App_GlobalResources folder? If the latter, then I will need to open another discussion for all my other issues -- or implement some cruder form of localization for the regex stuff.
Thanks in advance.
Jerad
This is the solution we came up with:
public static class ResourceHelper
{
public static string GetString(Type resourceType, string resourceName)
{
return new ResourceManager(resourceType.FullName, resourceType.Assembly)
.GetString(resourceName);
}
public static string GetString(Type resourceType, string resourceName, CultureInfo culture)
{
return new ResourceManager(resourceType.FullName, resourceType.Assembly)
.GetString(resourceName, culture);
}
public static object GetObject(Type resourceType, string resourceName)
{
return new ResourceManager(resourceType.FullName, resourceType.Assembly)
.GetObject(resourceName);
}
public static object GetObject(Type resourceType, string resourceName, CultureInfo culture)
{
return new ResourceManager(resourceType.FullName, resourceType.Assembly)
.GetObject(resourceName, culture);
}
}