invoke web service from winfomrs - c#

I want to invoke a web service from my winforms application in visual studio 2012. So, I have added a service reference to my web service in my project. This service contains two methods. How can I can invoke those methods from my c# code ?

You should be able to call it as follows:
using Your.Service.Namespace;
// ...
IYourService serviceClientInstance = new YourServiceClient();
serviceClientInstance.SomeServiceMethod();
PS: You can see info about the service and available methods by right clicking the reference (under Service References), and selecting View in object browser. Among other things, you should see a class YourServiceNameClient there, which should have been generated for you, which you can use as above.

Related

How to access ServiceStack based web service from visual studio webform

I'm having trouble understanding how to consume an existing ServiceStack based web service (https://cert.web.transaction.transactionexpress.com/TransFirst.Transaction.Web/api/). I am using a standard vstudio .net 4.6 aspnet website c# form.
I tried adding the base service uri as a service reference to my existing project (Website > Add Service Reference > URI) but on building my solution I receive error: [Error: failed to generate code for the service reference. Cannot import wsdl:portType...].
I would like to think that I can interact with this service without manually building object definitions, so I must be missing a step.
Two questions:
1. Has anyone else worked with this particular service? Or can you suggest how to generate object definitions from this service?
2. Am I incorrectly assuming that generating the object definitions will give me full VStudio intellisense on my httpclient?
Since this is a ServiceStack Web Service you can use C# Add ServiceStack Reference to generate a Typed API in C# which you can use with ServiceStack's C# Service Clients.
The BaseUrl for this Service is:
https://cert.web.transaction.transactionexpress.com/TransFirst.Transaction.Web/api/
So if you install ServiceStack VS from VS.NET Extension gallery:
You can create a Typed C# API by clicking on Add ServiceStack Reference on your project:
Then you can use the Typed DTOs with ServiceStack's generic Service Clients, e.g:
var baseUrl = "https://cert.web.transaction.transactionexpress.com/TransFirst.Transaction.Web/api/";
var client = new JsonServiceClient(baseUrl);
var response = client.Post(new CreateCustomReport { ... });

Service Reference in Silverlight don't show all of functions defined in WCF Service

I want to retrieve data from a database using a WCF service and service reference in my Silverlight project. All things that I do are:
created Linq-to-SQL file and add server connection then drag some table from server explorer to PersonDataClass.dbml file
Create WCF service
Implemented the functions defined in the interface:
created a Service Reference named DBServicesRef
but in my code I can access just one function of the WCF Service, just the getPersonComplete service method :
I searched the web but I am beginner in Silverlight :)
I clean, build, rebuild the project, update DBServiceRef (with check or uncheck reuse type in referenced assemblies ) or even delete and create files but I can not insert any value to database :( because I can not access the addPersonComplete service method to handle it .
Your addPersonRecord does not return any value. Therefor it will not get it's own event handler. It will use a generic handler.
When you've written the += after webService.addPersonCompleted just press tab twice and you should get a new function with the correct signature automatically.

I am trying to consume a PHP SOAP service from C# and create a class wrapper in VS 2010

I've been tasked with creating a class wrapper for a SOAP service, the idea is that you'll be able to treat it as a regular class. The main reason for this is that the WDSL for the SOAP service contains only one method and it's got 5 parameters and it's only kind of OO so you'd have to know all the method calls really well and it's a bit hard to remember them all.
OK, so I've tried adding a web reference, now web references can now be added as service references in VS 2010. You click add service reference advanced etc and it puts in a service reference. Great. Unfortunately if I try and access this from a class I can't.
I can build a console app and put code in the main procedure and access the method of the SOAP service fine but when I add a reference to a class library the intellisense won't allow me to select anything. I'd instantiate an instance like so:
SOAPService.webServiceService ws = new SOAPService.webserviceService();
ws.
and then the intellisense refuses to kick in. If I do the same in a web project or a console app then I can access it fine. I've added the namespace I've done all kinds of things. Also, I can add a web reference and get a DISCO file whenever I create a web project.
OK, also while I'm on the subject I also need to pass credentials to the web service in PHP.
The problem is that in the past I'd create some .net system credentials and add these and it would usually pass through if I was connecting to another .net service.
How should I be sending them to a PHP web service? I always get either invalid username/password combo errors or envelope malformatted error types
Thanks
Mr. B
So the intellisense is not working, but if you add the method in and try to use it does it work, or produce an error?
With regard to diagnosing authentication issues try using fiddler to view the SOAP messages that are being sent, and to view the reply. Do you have some other software that connects and authenticates to that service? Use fiddler to look at the SOAP messages and compare them to see if the header is different etc.
I'd normally do it like this,
using (Service service = new Service())
{
service.ClientCredentials.Windows.ClientCredential.Domain = "domain";
service.ClientCredentials.Windows.ClientCredential.Password = "password";
service.ClientCredentials.Windows.ClientCredential.UserName = "username";
}
Also with regard to the service working or not in general use fiddler if you have any problems, you can see the SOAP messages and it often gives you a clearer message.
I know in IIS you can turn on failed request handling that also gives you an insight from what is going on at the server end, perhaps you have some form of logging too for your php service?

ASMX Web Reference not Updating After Service Return Type Updated

I have a webservice - called MyCompany.WebService1
I reference this using a web reference in my ASP.net web application.
Theres a method called "GetDeal" in this web service, that returns a "Deal" Object.
The deal object currently looks (for example) like this:
public class Deal
{
Public string Name {get;set;}
Public string Description {get;set;}
}
This class is in a different assembly: MyCompany.Model
The web service references this assembly.
In my web app, I can call the GetDeal method.
This returns Service1.Deal (service1 is just the name of the web reference)
I can access both properties above.
I have now changed the Deal class, and added a couple more properties.
However, I can't see these new properties in my web application.
I've updated the web service in the web application.
I rebuilt the web service several times, tried removing the MyCompany.Model reference and re-addding it etc...
I can't figure out what has changed... This was working - I have changed the model before, and it's updated the reference correctly...
Anything I've missed?
As long as the following points are fulfilled, this should work:
the new property is marked as Public and must be read/write (must have a getter and a setter)
you have compiled the host web application (the web app which exposes the web service).
(You can try calling the web service in a web browser to check whether the new property is visible).
you have updated the web reference the client application (and rebuilt the app)
In addition to what Martin suggests, you have to actually run the updated service.
I recommend you look at the WSDL to see if the changes took effect. Add "?wsdl" to the web service URL in the browser, and look to see if your new properties appear in the XML Schema at the top.

Using Webservice classes in Silverlight when adding service reference instead of web reference

Scenario:
I am using Silverlight 3.0 as client for a web service.
Design:
The server has a class named DeviceInfoService which has the basic functionality of getting the list of devices, getting the properties of devices etc.
When I open an ASP.NET project and try to add a web reference, I can find an option to add a "Web Reference". After I add the web reference this way, I am able to access the DeviceInfoService class by creating it's object and then accessing it's methods.
Web Reference v/s Service Reference:
Coming to Silverlight: when I try to add a service reference, there is no option to add a web reference. Going with Service Reference, everything works fine till WSDL file is downloaded. People say that I can get this option by going back to .NET 2.0, but probably Silverlight won't work in .NET 2.0
The Problem
Now when I try to access the class DeviceInfoService , I am not able to find it. All I get is Interfaces -- DeviceInfoServiceSoap and DeviceInfoServiceSoapChannel. Classes named DeviceInfoServiceSoapClient.
The methods GetHostedDevices and GetDeviceInfo are no longer available. All I get is GetDeviceInfoRequest, GetDeviceInfoRequestBody, GetDeviceInfoResponse and GetDeviceInfoResponseBody.
I googled a lot how to use these four classes, only to find nothing. I want to get those 2 classes directly like in ASP.NET and not using those Request Response type.
You sound awfully confuse about some concepts.
How about you watch the following Silverlight.Net video and see if that helps?
How to Consume WCF and ASP.NET Web Services in Silverlight
What is web reference in ASP.NET is equivalent to service reference in Silverlight.
Here's an example of how to use a web service in Silverlight, e.g. the CDYNE Profanity Filter.
Add a new Service Reference to your project, URL is: http://ws.cdyne.com/ProfanityWS/Profanity.asmx?wsdl, leave the name as ServiceReference1.
Use this code behind to call the service (which was implemented to be asynchronous):
public MainPage()
{
InitializeComponent();
string badText = "I wonder if the filter will filter this out: shit bad luck";
ServiceReference1.ProfanitySoapClient client = new ServiceReference1.ProfanitySoapClient();
client.ProfanityFilterCompleted += new EventHandler<ServiceReference1.ProfanityFilterCompletedEventArgs>(client_ProfanityFilterCompleted);
client.ProfanityFilterAsync(badText, 0, false);
}
void client_ProfanityFilterCompleted(object sender, ServiceReference1.ProfanityFilterCompletedEventArgs e)
{
string cleanText = e.Result.CleanText; // Web service callback is here
}
And you've got a web service up and running in Silverlight!

Categories

Resources