Client App with WCF to consume ASMX - c#

I have a webservice with .NET 1.1 (old school ASMX) and I am creating a client app to connect to it and use its services.
From what I remember from the last time I had used Visual studio -which was 2003 version!- I can add a WebReference to it and easily use it. Tried it . it still works.
but it looks like things have changed in 2008 and now we also have WCF. so I can add it as a Service Reference. but with this new method I could not find a way to create an Instance object to the ASMX service and call its methods... how do we accomplish the same thing with WCF?

Ok. done:
we should create a ServiceSoapClinet . an example from my play app:
using (LatestServiceSoapClient proxy = new LatestServiceSoapClient("LatestServiceSoap"))
{
label1.Text = proxy.Welcome();
}

Related

C# call SOAP webservice from console application

This seems very trivial, but it is not working for me at all. I am attempting to call a soap web service from within my c# console application. The app is built for .net 4.5. Here's what I did:
Added the service reference to the project in visual studio 2013 by pointing it to the wsdl. It finds the Service and it's operations fine.
Attempt to create an instance of that service by doing the following:
ServiceReference1 s = new ServiceReference1();
I get the following error code:
Project1.ServiceReference1 is a 'namespace' but is used like a 'type'
Any ideas? I've searched for this for a while and can't come across someone having the same problem with a real solution. I will provide any more info needed.
If you already added the service reference to the project you see the reference. In this case you left a default name 'ServiceReference1'.
Now you want to call the web service's methods, for this you have to instantiate a SOAPClient.
ServiceReference1.YourWebserviceNameSoapClient client = new ServiceReference1.YourWebserviceNameSoapClient();
client.HelloWorld(); // call of webmethod
now you access the webmethods under the 'client' object.
When you create a service reference, Visual Studio 2013 will generate a proxy class you can use to transparently call into the service. The default proxy namespace is your_project_name.ServiceReference1. The type is the name of your service.
For an example service http://localhost/YourService.svc.
You generate the Service Reference ServiceReference1 from your console project ConsoleApp. The generated files have the namespace ConsoleApp.ServiceReference1. The type is YourService.
var service = new ServiceReference1.YourService();
will return an instance of the proxy generated by Visual Studio. Then you will be able to call any of the service methods.

How to create and execute .net web service clients?

I need to create and execute a C#.net client that consumes a web service (wsdl).
I have used the wsdl.exe tool:
wsdl.exe /language:CS /out:c:\myTests\ http://localhost:8080/myTestService.wsdl
getting as output a .cs file that contains several methods but no main.
How do I create a client that invokes the remote method of the web service?
with no prejudice on why you ask this question and why are you implementing this thing of the past, you might want to try this :
var client = new myTestService();
var result = client.AvailableMethod();
hope this helps.

C# soap web service and Java client

I have problems with writing Java client for wshttpbinding web service.
I wsimport-ed .wsdl and i try to
TestService iface = new TestService();
ITestService implmt = iface.getWSHttpBindingITestService();
then i call web service method set
implmt.set("s", 1);
And i get
Exception in thread "main" javax.xml.ws.WebServiceException:
java.net.SocketException: Connection reset
I cannot change server side, it must be as is. So change to basicHttpBinding is not possible (if i change it i don't have any problem but alas)
Client must be made in Java.
Oh ok I solved it. I imported METRO .jar files to build path and moved them to top (to be first)
It is crucial to place those jars on top.

Custom SharePoint 2010 WCF Service - How to set MaxReceivedMessageSize parameter

I have developped a custom WCF Web Service within a SharePoint 2010 Visual Studio empty project.
My web service is working well. The problem is related to the size of the request I can send to this web service. I have realized that is something around 300Kb. If I go bigger than that, the service/client is sending me an exception.
I've looked around on the web and see that the MaxReceivedMessageSize setting may be my solution. I've tried using a FeatureActivated method to set this information using this kind of request:
// increase maximum size of requests to this web service: http://msdn.microsoft.com/en-us/library/ff599489.aspx
SPWebService contentService = SPWebService.ContentService;
contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;
SPWcfServiceSettings csomWcfSettings = new SPWcfServiceSettings();
csomWcfSettings.MaxReceivedMessageSize = 10485760; // 10MB
contentService.WcfServiceSettings["PT-SP-P2S-DocumentCreator.svc"] = csomWcfSettings;
contentService.Update(); // access denied thrown here!
With that code, I have an Access denied (I'm actually the Site Collection Administrator).
I also know that this parameter may be set in the app.config of web service host but, in SharePoint, where to I need to change this parameter.
I think you should make this change in the web.config file of the Web Application in which the feature is activated. SharePoint provides APIs to make web.config changes. In fact, using APIs to make changes to your web.config is preferred option because SharePoint uses Timer Job and makes same updates to all Web Front End servers in your environment. There are 2 ways to make changes to web.config as described here:
http://msdn.microsoft.com/en-us/library/ms460914.aspx
In your case, since you want to make the change only when your feature is activated, you would take the API approach as documented here: http://msdn.microsoft.com/en-us/library/bb861909.aspx

Connect to Unknown SOAP Web Service

I would like to build an app in C# that connects to an Apache AXIS web service and performs the following operations via SOAP.
Login in to the server.
POST string data to server
Receive and display server response
Here's the tough part. I do not have access to the server, nor do I know where the .JWS file is located on the server. I was able to get to the WSDL file in my web browser, so I know a "Login" operation exists as well as an operation to take in data.
I have tried accessing the web service via URL, but I keep getting this message:
Hi there, this is an AXIS service!
Perhaps there will be a form for
invoking the service here...
In summary, is there anyway I can connect to this web service when all I have is the URL of the WSDL file? Are web services accessible via URL?
Thank you
Use WCF, and generate client proxies to the web service using the svcutil.exe tool.
running svcutil.exe http://url.to/webservice?WSDL the_wsdl.wsdl /language:C# should generate proxy classes you can use in your C# project, and you'd call the service e.g. like
BasicHttpBinding myBinding = new BasicHttpBinding(); //might not even need these
// 2 lines if you ran svcutil.exe directly on the web service URL
EndpointAddress myEndpoint = new EndpointAddress("http://url.to/webservice");
TestClient client = new TestClient(myBinding,myEndpoint); //the generated classes
// svcutil.exe created
client.SomeOperation(42); // call an SomeOperation of the web service
Thanks for everyone's help. Looking back on this question, I can see how severely confused I was. Here is the solution I followed.
Assuming you know the URL of the WSDL file of the service you wish to connect to then just do the following.
Boot up Visual Studio
On the top toolbar navigate to Data -> Add New Data Source then choose Service in the new dialog
In the address bar, enter the URL of the wsdl file (EXAMPLE: http://server.com/services/displayName?wsdl)
Near the bottom of the dialog, change the namespace to something relevant to the project (EXAMPLE: sampleService)
Now Visual Studio should compile the client proxies for you that you can use to access the web services on your server. To access one of the services, all you need to do is create a new object from the class.
//Example
sampleService.ClassName test = new sampleService.ClassName();
test.displayName("Jack");
See http://msdn.microsoft.com/en-us/library/bb552364.aspx for a starting point

Categories