i write a simple webservice code in asp.net when i build the service and run the service it is working fine. when i try to access the webservice it is giving some problem , problem means i am not getting that method (webservice method). After completing writing the webserivce i take a asp.net page (.aspx) and in solution explorer i add a webservices and it is added successfully. but when i adding namespace it is not getting the service name ( i not able to add the namespace of websercice
I am not exactly sure what could be the problem but you should only need to do the following to use the web service:
// Look at what you named your web reference, in my example it is
// called MyWebService. Check your solution explorer for the actual name.
// This is the alias you should be using.
MyWebService.YourWebServiceName ws = new MyWebService.YourWebServiceName();
var result = ws.MyMethod(someparameter);
Related
Recently I've been starting with Asp.net, particularly Web Form application. And in the application, I need to reference a dll produced by Matlab deploytool (including a .m function I wrote myself).
I copied all relevant dlls to the Bin directory, add reference in the application and using the corresponding namespace. The compiler works fine but a TypeInitializationException was thrown in runtime when trying to initialize an instance of my matlab class.
BTW, in a Windows Form application it works fine amazingly, but not in Web Form applcation. Is there anything I missed when calling a matlab dll? e.g. Add XML comment in Web.config ?
Here is the key code from where the exception was thrown:
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using diseases; //this is the namespace of urinary_bladder created by deploytool
...
MWArray [] value = new MWArray[8]; // This statement works well
urinary_bladder ub = new urinary_bladder(); // A 'TypeInitializationException' was thrown here
I'll appreciate any of your replies, thx a lot.
I just started to get into ASP.net Web API (created MVC 4 project, Web API application, in .net 4.5).
I need to make custom handlers in particular. All I know is that we create one (inherit DelegatingHandler), and register it in App_Start/WebApiConfig.cs's Register function.
Where do we save such a handler (MyMessageHandler), though? No tutorial or book I've come tells me this. I tried to save it in the App_Start folder with the same namespace as WebApiConfig, but it says that MyMessageHandler cannot be found:
config.MessageHandlers.Add(new MyMessageHandler()); // MyMessageHandler is not found.
Where you store MyMessageHandler.cs doesn't matter at all, as long as you get your references in WebApiConfig right. I personally store them like project_root/MessageHandlers/MyMessageHandler.cs
I've created an asp.net web service and am trying to test it using my client. The web method I'm currently testing returns a custom object named GetAllTicketsSinceLastPullDateResult, which contains one ArrayList of custom clsTrip objects, and a custom object called FaultResponse. This is how I'm using my client:
ServiceReference1.ServiceSoapClient myClient = new ServiceReference1.ServiceSoapClient();
ServiceReference1.GetAllTicketsSinceLastPullDateResult result = new ServiceReference1.GetAllTicketsSinceLastPullDateResult();
result = myClient.getAllTicketsSinceLastPullDate(myUser);
But I get the following error:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type clsTicket was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
I Google the error and most of the answers I find have to do with serializing derived classes. But my clsTicket class is not a derived class. What can be causing this error? How do I use XmlInclude or SoapInclude?
Thanks in advance!
Okay I finally got it to work, I ended up putting the following line:
[XmlInclude(typeof(clsTicket))]
Between [WebMethod] and my method's definition. So far so good.
I don't think you need to 'new' result:
ServiceReference1.GetAllTicketsSinceLastPullDateResult result;
result = myClient.getAllTicketsSinceLastPullDate(myUser);
Also, how do you know the error isn't on the server?
Can you call the function with a web browser?
Have you updated your service since initially adding the reference to your project? If you're using Visual Studio's "Add Web Reference" feature and you update the service, often times there is a configuration or parameter chance, which can generate SOAP errors.
Try right clicking on the Web Service in question through visual studio and select "Update" option. Recompile the app and see if that resolves your issue.
I created a web service recently and am using unity to inject my object dependencies. My composition root is the Application_Start in the web services and am using the web.config to do my object to interface mappings. Everything was working fine, however after i loaded my project into tfs i keep getting an error stating that it cant resolve one of the interfaces. I removed the code to register my objects from the web.config and regsistered them in code instead to test and it all works fine. Any ideas what the problem is. Any ideas how i can troubleshoot this problem.
Before TFs :-
UnityContainer uContainer = new UnityContainer();
UnityConfigurationSection Section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
Section.Configure(uContainer, "CentralRepositoryContainer");
Application["uContainer"] = uContainer;
Amended code which works fine :-
UnityContainer uContainer = new UnityContainer();
uContainer.RegisterType<ICentralRepositoryLifeTimehelper, CentralRepositoryLifeTimeHelper>();
uContainer.RegisterType<IJobsHandler, JobsHandler>();
Application["uContainer"] = uContainer;
I don't know the problem, but to troubleshoot print out all the Unity containers registrations and see what's missing/changed.
Use the code sample from Retrieving Container Registration Information
I want to write a few web tests (over WatiN/Selenium + CassiniDev web server) for my asp.net web application.
Problem I encountered is that I dont know what to do in such situations:
there is a page where user can click the button to call some third-party service. In my web test i want to create mock of this service, which will always return static value (some value in these test case and other value in other test case).
How can i do that?
Currently i use IoC/DI container Microsoft Unity. And my pages gets his dependencies in a manner described in http://msdn.microsoft.com/en-us/library/ff664622%28v=pandp.50%29.aspx.
The only solution that comes to my head is: place all dependencies in web.config for each test case and copy necessary web.config on SetUp of test. This solution completly painful!
Any ideas?
I use WatiN and Cassini-dev in my integration tests as well and have had to deal with similar issues. In my setup fixture I deploy my Asp.Net web application to a temporary folder in my test folder which allows me to play around with the configuration before starting up cassini-dev. I use Windsor for my CI which allows me to change injected components at the configuration level. You may also be able to acheive this with Unity.
If the service you are referring to is a web service you just mock out a web service using the interface you have been coding to.
Here are the steps that I take when running my integration tests:
Create a temp web directory
Publish the Asp.Net web application to the temp directory (I use MSBuild to do this)
Deploy temp database (Using MSbuild and database projects but could be done a number of ways)
Deploy temp membership database (see my blog post on how to do this in code)
Update the web.config of the deployed Asp.Net web application to point to the temp databases and change any other settings relevant for testing.
Start up the website using Cassini-Dev. I also hit the site with a http request so that I can verify the site is up before running any tests.
Run the tests.
After running the tests you should clean up.
Stop cassini-dev
Delete the temp hosting folder
Delete the temp databases. I use Sql server SMO objects that allow me to query the Sql Server which I use to delete up any old databases that have been left lying around after any previously failed test runs.
How to deploy a website using MSbuild in code
var properties = new Dictionary<string, string>
{
{"Configuration", isDebug ? "Debug" : "Release"},
{"WebProjectOutputDir", tempHostingDirectory.FullName},
{"DeployToDatabase", "true"},
{"OutDir", Path.Combine(tempHostingDirectory.FullName, "bin\\")}
};
using (var engine = new ProjectCollection(properties))
{
engine
.LoadProject(<web project path>, "4.0")
.Build(new[] {"Build", "ResolveReferences", "_CopyWebApplication"});
}
Unity configuration section usage: http://www.pnpguidance.net/Post/UnityContainerUnityConfigurationSectionAppConfigWebConfig.aspx
Generating asp.net membership database in code: http://bronumski.blogspot.com/2011/06/generating-creating-aspnet-application.html
Msbuild ProjectCollection on MSDN: http://msdn.microsoft.com/en-us/library/microsoft.build.evaluation.projectcollection.aspx
It sounds like you are trying to mock a web service.
Web services usually inherit from MarshalByRefObject, this means you can create a mock by inheriting from RealProxy to create a transparent proxy that pretends to be the webservice:
class Mock : RealProxy
{
public Mock()
: base(typeof(IStuff)) { }
public IStuff GetStuff()
{
return (IStuff)GetTransparentProxy();
}
public override IMessage Invoke(IMessage msg)
{
IMethodCallMessage message = (IMethodCallMessage)msg;
// the message object provides the MethodInfo that was called
// as well as the arguments.
// <Insert logic here>
return new ReturnMessage(new NotImplementedException("comming soon to a test near you ..."), message);
}
}
I belieave NMock2 uses RealProxy for it's mocks, so you should be able to use it to mock the web service instead.