Generate C# proxy call from wsdl + xsd - c#

Hi i need generate web service proxy for C# client. Web service is java. I have wsdl + xsd file for web service.
I try use wsdl.exe tool
wsdl /out:D:\filename.cs /protocol:SOAP12 C:\filename.wsdl
But problem is that some definition are in xsd file. how to merge it. I think it is new standard

Have a look at the /par switch for the WSDL tool

I know it's been a while since this question was asked, but I also needed to use an XSD with my WSDL today, so this popped up in my search.
I ended up using wsdl.exe like this:
wsdl C:\filename.wsdl C:\filename.xsd /out:C:\filename.cs /protocol:SOAP12
If nothing else, it might be useful to someone else someday :-)

Related

Implementing a SOAP web service

I have a WSDL definition for a SOAP service and I have successfully generated *.cs file from it using SvcUtil.
Implementing client is quite straightforward - I just need to call the necessary functions from the generated *.cs and that's it.
Implementing server seems more complicated. As I understand I need to implement an interface from the generated *.cs and then use some magic to turn it into the web server.
But I don't need a new web server, I already have a web server written in C# which already has many functionality unrelated to the SOAP service that I need to implement. I don't want to create another web server but I want my SOAP service to be just a part of my existing application (server), that is my server can answer e.g. requests http://example.com/request1, http://example.com/request2 etc. and I want this SOAP service to be just http://example.com/request3.
Since HTTP is already handled by my server I don't need .NET to handle it for me, basically my server can accept client connections and call the necessary handler based on the URL. I have a handler for SOAP request which looks approximately like this:
MyResponse HandleSOAPRequest(MyRequest request)
{
// 1. parse soap message from request.body
// 2. process it
// 3. generate response, serialize it in SOAP format and return it
}
The question is - can I rely on WSDL definition and .NET libraries to do it?
Currently I'm parsing SOAP request using XDocument and manually extract fields from it and serialize using simple string concatenation. Using .NET built-in functions to serialize or parse XML doesn't work. That is if I try to serialize response from an object of the class defined in the generated *.cs file then produced XML is different from what is expected by the protocol, similarly, if I try to parse request as an object of the class defined in the generated *.cs file I get error because XML parser expects different format. This applies to both the SoapFormatter and XmlSerializer.
Since .NET can implement client this means that everything that is necessary to parse and serialize SOAP messages is already implemented, I just need to figure out a way how to use this functionality.
The documentation for ServiceModel wasn't very helpful.
The easiest way would be to start the service via the ServiceHost:
ServiceHost host = new ServiceHost(typeof(YourService));
host.Open();
(I assumed here the configuration will come from the app.config and will not be setup in code like in the linked example below.)
How to: Expose a Contract to SOAP and Web Clients
The only drawback of this is that the application has to run with admin rights or otherwise a weird cofiguration is necessary.

Using PHP nuSOAP webservice in C#

I am working on windows phone project in visual studio 2012 for windows phone.
I am trying use PHP NuSOAP webservice by adding Service reference.
Here I followed this sample app. In general the VS will create Reference.cs file while adding webservice. You can see reference.cs file contents of dictionary(Sample) app HERE
The Reference.cs of my webservice of my project HERE. In my Reference.cs file the interface SomeMobileServicePortType is empty.
In Line 19.
public interface SomeMobileServicePortType {
}
Because of this I not getting any methods of webservice to access in my project. But while adding reference in Add service Refernce dialogue it is showing the methods contains in PHP NuSOAP webservice.
I created new instance of webservice class..
ServiceReference1.SomeMobileServicePortTypeClient client = new ServiceReference1.SomeMobileServicePortTypeClient();
What is the wrong with PHP webservice. I tried some more webservices [in particular asmx, I didn't get any sample PHP NuSOAP webservice to try] which are working fine. Can any one tell me How to use PHP NuSOAP service using C#.
==================================================================================
Edit:
We are using NuSOAP PHP webservice.
I believe that there is no problem with Webservice. I can't share the WSDL file right now.
Here I got the sample that explains using PHP NuSOAP in C#. I tried with this webservice link. This reference also not giving any methods. The interface is empty like this.
public interface HirdWebExamplePortType { }
So my guess is while using NuSOAP service it is not working in IDE Visual Studio.
Here is my sample windows phone project. Please try this & suggest me what I am doing wrong.
The project you supplied is not compatible with this kind of SOAP-Service.
If you add the service to e.g. a Console App it works fine:
but if you add it to your project (WP Silverlight):
Check if you can disable SOAP encoding on your service.
It does support RPC/Literal soap style so we need to change the style from RPC/encoded to RPC/literal. This is actually really easy: Open the wsdl file and modify the input and output operations from
<soap:body use="encoded" ..../>
to
<soap:body use="literal" ..../>
Reference:
Just go through the below link:
http://guruce.com/blogpost/hosting-webservices-on-wec-using-gsoap-windows-phone-75-mango-client-application#comments

Best way to start Contract First WCF or Web Service?

I've been given a WSDL file and several XSD files to build a web service for. Right now I'm trying to just get it setup to receive requests and respond.
My experience with WebServices is limited to the old asp version with an asmx file etc.
There is a lot of information in the XSD files, I don't want to build out the classes by hand, nor do I really understand exactly what that would entail anyways (I'd imagine just an xml serializable class but haven't looked into it).
Where do I start with this? I looked into WCF but its completely foreign to me so I'd kinda rather use the old style, but I'm struggling to find any info on how to set that up or get a head start with automated generation of classes from the XSD files.
I did try WCF a bit, but WSCF blue gives me errors (Cannot import wsdl:portType) when I try to generate the WebService code. And svcutil.exe will generate some of the XSD file info but not all of them for some reason.
So two questions:
How can I generate some stub classes from XSD files to get this going
A tutorial/walkthrough for generating a WCF service from a WSDL and multiple XSD files that does not use wscf blue?
Assuming you have a WSDL to start with, you can do the following. I did this when tasked with implementing an intermediate dispatch layer on top of an existing web service. The new service should expose the same interface as the original service but perform different functions internally. Note that I am talking about "classical" WCF services here (SOAP-based).
Step 1: Create code for the service interface from the WSDL
wsdl.exe /si /out:<targetfolder> <url-to-wsdl>
This generates a .cs file that contains the interfaces and additional data types (for transfer objects). Note that this file is not WCF-ready yet as wsdl.exe seems to assume you want to create an old .asmx service.
Step 2: Import interface code into your project
Add the generated file to your project. Add attributes for making the interfaces and their operations WCF-ready. You need to add [ServiceContract] to the interfaces and [OperationContract] to the operations.
Step 3: Create the WCF service
Create a WCF service (.svc file) and get rid of the generated interface. Instead, make the service implement the contract(s) from the generated interfaces. Now, you can implement the new functionality.
Step 4: Adjust the remaining binding, authentication settings etc. to match the original web service.
You can use the svcutil.exe to generate proxy .cs classes and app.config files for your client part of the service setup, from the wsdl and xsd files.
Following is a cmd that will will generate a proxy from the visual studio cmd line:
svcutil.exe c:\OutputFolder\ /o:serviceproxy.cs /config:app.config "C:\WSDL And XSD Folder\*.wsdl" "C:\WSDL And XSD Folder\*.xsd"
These might help you get started - if you plan to go the RESTful route:
http://www.codeproject.com/Articles/571813/A-Beginners-Tutorial-on-Creating-WCF-REST-Services
http://msdn.microsoft.com/en-us/library/bb412178.aspx
http://nareshkamuni.blogspot.com/2011/12/window-communication-foundation-wcf-in.html
More in depth - http://www.thatindigogirl.com/ - Michele Leroux Bustamante from a few years ago.
Not so much a walkthrough - but has good info http://rest.elkstein.org/2008/02/what-is-rest.html

Getting "raw" xml from webservice

I'm trying to to generate web service proxy class using ServiceContractGenerator.
But the problem is that i want to recieve a "raw" xml from webservice (it may be a string or XmlNode, doesnt matter).
Is there any way to modify web service contracts before generating proxy or do something else to get what i need?
If you are talking about Wsdl then it should either been exposed from the webservice. or rather provided to you via .wsdl file.

Defaulting to different URLs when Generating Web Service Proxy with WSDL.exe

I have numerous Web Services in my project that share types.
For simplicity I will demonstrate with two Web Services.
WebService1 at http://MyServer/WebService.asmx
webService2 at http://MyServer/WebService.asmx
When I generate the proxy for these two services I use:
wsdl /sharetypes http://MyServer/WebService1.asmx http://MyServer/WebService2.asmx
/appsettingurlkey:WebServiceUrl /namespace:MyNamespace /out:MyProxy.cs
The problem is that the appsettingurlkey is the same for each Web Service
in the proxy file. I want to be able to specify multiple
appsettingurlkey parameters. How is this accomplished? I figure
since the /sharetypes parameter became available, there should be a
solution for specifying the appsettingurlkey specifically for each
Web Service identified.
If this is not possible with the wsdl.exe, what would you propose I do? I would rather not update the generated code that wsdl.exe outputs and I don't want to go through my whole application passing in the Url to each instance of the Web Services.
The proxy classes generated are partial classes, so my solution would be to add your own constructor in a different (non-generated) code file, which explicitly reads a different setting for each proxy.
To suplement Elijah's own answer, here's the email answer I gave him.
I had to blog it because the XML didn't paste well into this text box: http://www.rickdoes.net/blog/archive/2008/09/29/wsdl-shared-types-and-configuration.aspx
Ahh, instead of creating another partial class with an overloaded constructor passing in the Url, the following additional parameters to the wsdl.exe will solve my problem...
wsdl /sharetypes http://MyServer/WebService1.asmx http://MyServer/WebService2.asmx /appsettingurlkey:WebServiceUrl /namespace:MyNamespace /out:MyProxy.cs /appsettingurlkey:BaseSoapUrl /appsettingbaseurl:http://MyServer/
If the web.config has a BaseSoapUrl appSetting, then it will use that to replace the http://MyServer/ sub string from the MyProxy.cs. If the appSetting is not present, then it will just use the path provided in the wsdl.exe (example: {BaseSoapUrl}/WebService1.asmx when using the appSetting or http://MyServer/WebService1.asmx when not using the appSetting).
A thanks goes out to Rick Kierner for pointing me in the right direction.

Categories

Resources