Changing "web reference" to "service reference" changes method signature - asp.net

I'm helping out a colleague on this one so if I'm missing some details that's why.
We have an asp.net 3.5 web application calling a WCF service. Originally the app used a "Web Reference" to register the service however after having some trouble and burning an incident with Microsoft their solution was to replace the "Web Reference" with a "Service Reference" to the WCF service.
This is great except the problem is that when we create a Service Reference, the method signatures are different than they were when a Web Reference was used.
From what I've read this may be expected, however in our case this would mean some significant changes to the application and of course it was due yesterday...so...
...I'm wondering two things:
Is it normal/expected that method signatures will change based on the reference type?
Is there a way to create the Service Reference that will generate method signatures identical to the original Web Reference?

You could create another layer between your current Web Reference calls and the new Service Reference proxy.
Create your service ref with a different name and/or namespace then what exists today.
Create a class with the name/namespace of the old Web Reference proxy.
Create the method signatures in the new class and wrap your calls to the Service Reference proxy.
Does this make sense. It's a very simple Adapter pattern.

Related

calling SOAP API + WSDL with static website in asp.net

The project I'm holding is asp.net website with static content [aspx files]
SOAP WSDL to the web services is provided and it's built with java and I have added a service to the project using "Add Service Reference".
I am looking for a way to consume that API with the website so as I could not understand how to call and integrate the data out of service and locate it into HTML[.aspx] page.
I have worked mostly with MVC projects but in this case I have not found any clue on how to do that.
After looking for many resources, Here is a conclusion how i solved my problem in case anyone needed that later in WebForms and C#.
1.Add Service Reference to your project using the WSDL link
provided
now you have classes and functions identified to your project.
Import the namespace to your class or your webform page using corresponding syntax and after that you can instantiate object out of classes and use functions
using namespace.webserviceName; with class
<%# Import Namespace="namespace.webserviceName" %> with webForm page.
One more issue popped up while I was trying to connect to the service with TLS/SSL protocols using asp.net 4.0.The Exception I received was: "The request was aborted: Could not create SSL/TLS secure channel"
-To solve this refer to this question answer

Can I Send a custom class from asp .net 4.0 website to a WCF .net 4.0 service

I want to create a wrapper class called Report that contains dictionaries and lists and such in my website generated by 100-1000 fields from the website page, then send it to my WCF service.
I have tested my connected I can send a string or int and it works fine, I have not tried to send a custom class (im assuming the class would be attached BOTH to the website (ASP.NET 4.0) and the WCF service (.NET 4.0) in order to make this work.
The idea is to create the report class, fill it up with my data then send it to the wcf (the interface would have a [OperationContract] and then it would take a parameter of type Report, and then I could do something with that object on the WCF service side to pull data from dictionaries and lists from the object and send it to a database.
So I know right know my website and wcf are talking together as I have sent a string and returned an int it worked fine.
But I am wondering if I can pass over a class that I created (assuming both the website and wcf both have the same class file)?
As you need a confirmation by a totally trustworthy stranger on the internet, yes it works that way.
If you decide that listening to random people isn't going to help with the deadline, you may want to open a new WCF project in Visual Studio. It will generate a default service called Service1 that already does exactly what you want. It uses a user defined type in it's interface. Open a new ASP project and reference that service. The class will even be generated for you by the Visual Studio Wizard.
Hats off to the smart guys on SOF.com, but #Kairan - the class you made it in either Business Layer - this should have a parallel SOA layered Datacontract(aka class) and those fields which should have publicly available and entire class should be serializable ( which should not have fields which are not serializable- like sqlconnection.. . I know crude way of checking whether all classes are serializable or not of a ASp.net web application - Just set in web.config - and by navigating all pages, one can understand all the objects are serializable :)

add web reference in visual studio for a restful web service

I'm trying to add a web reference to a restful service, here is one sample URL:
http://dailymed.nlm.nih.gov/dailymed/services/v1/ndc/0409-3613-01/spls.xml
and I'm getting the following error (I'm guessing because I have no access to WSDL or DISCO they aren't listed on the API help page):
The document at the url http://dailymed.nlm.nih.gov/dailymed/services/v1/ndc/0409-3613-01/spls.xml was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'XML Schema' is 'The root element of a W3C XML Schema should be
I don't have access to this web service, it's run by the national library of medicine. Any thoughts on how I can add a reference within VS? Do I have to access this manually?
There is no standard metadata format to describe REST services. There's nothing similar to WSDL. Therefore, "Add Service Reference" or "Add Web Reference" won't work.
You'll have to look at the documentation of the service, or possibly at sample code, and build your own access layer.

Why is a Service Reference required in web application in addition to the class library that uses the service?

I am intending to provide access to a web service for an ASP.NET web application through a class library, and have been experimenting with a simple weather service.
In case it makes a difference I am using Visual Web Developer 2010 Express.
The interface between the web application and the class library is a simple string passed and string returned to a single method of a single class e.g.
String forecast = LibClassInstance.GetForecast("Madrid");
I added the Service Reference to the class library using AddServiceReference and created my call to the service through the automatically generated proxy classes. So far so good.
I then went to call my simple GetForecast method from my web application and got a long error message to the effect that the service might not have been configured in my project's Web.config file. After adding the Service Reference to my application project as well, it all worked as expected. I was hoping that the service behind the class library code would be hidden from its clients.
Can anyone tell me why it was necessary for me to add a service reference to the web application as well as the class library in order to get it working?
Can anyone tell me why it was necessary for me to add a service reference to the web application as well as the class library in order to get it working?
It isn't necessary. But you do need to configure the service in Web.Config - as a starting point you can copy the system.serviceModel section that was generated in the app.config of your class library when you added the Service Reference.

How to return or cast the same type from web services

I've created a web service in asp.net (ASMX) for caching purposes.
The website that uses this WS, requests and gets a shared type object (that is, both the website & webservices use the same DLL that includes that object type).
but what happens is, that the website gets the response from the webservices and the type is being wrapped by the WS's name space.
for instance.
If I have in the shared DLL a class Core.Person
the webservice returns Core.Person.
the website (even it knows the core.person) will get WebServiceNS.Person
This won't allow me to cast it.
how can I still use the same original DLL namespace when getting those objects from the WS?
thanks
You should not be using ASMX services for new development. It's a legacy technology.
In addition, it has no ability to do what you want. WCF, on the other hand, can do it trivially.
One solution can be, instead of using ASMX service use WCF service. WCF service allows you to use existing structure for the webservice call. In that case you will not need to create reference of your service. You can use same Core.dll in both the projects.
If you need any help in this, post a comment.
Hope this works for you.
Actually when we add a webservice reference VS generates a stub creating classes for all the objects required by WS. (These are on the basis of WSDL file hosted on the web server). All our communication with the webservice is done using this stub. I guess you'll have to write your own copy constructor for this.

Resources