Generate WSDL for WCF service
- Hello,
I want to write a very simple WCF web service in VS 2008 and generate the WSDL for it.
Is there a way to do it in WCF web service?Something like we do it in asmx web service.
Answers
- Hi Rachana,
I have re generated the contracts and have a made a project for that. I have uploaded your sample in the following location.
http://cid-05c2e50f2c5140c1.skydrive.live.com/self.aspx/.Public/WcfService4.rar
Let me if it helps.
Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/- Marked As Answer byRachanaD Sunday, November 08, 2009 3:50 AM
- Hi Rachana,
i just used >svcutil /dataContractOnly c:\GetPolicyDetailResponse.xsd to generate the contracts. thats all i did. the contracts you generated had datasets in them. i am not how generated(may be thru xsd.exe?). all i did was to use >svcutil /dataContractOnly c:\GetPolicyDetailResponse.xsd and generate contracts. you can try it as well
Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/- Marked As Answer byRachanaD Sunday, November 08, 2009 3:51 AM
All Replies
- Sure, all you need to do is to add on the host a ServiceMetadataBehavior, and set its HttpGetEnabled property to true.
public class Post_d5f58dd7_1f35_40dc_9dcf_97b894b64444 { [ServiceContract] public interface ITest { [OperationContract] string Echo(string text); } public class Service : ITest { public string Echo(string text) { return text; } } public static void Test() { string baseAddress = "http://" + Environment.MachineName + ":8000/Service"; ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress)); host.AddServiceEndpoint(typeof(ITest), new BasicHttpBinding(), ""); host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true }); host.Open(); Console.WriteLine("Host opened; WSDL at {0}?wsdl", baseAddress); Console.Write("Press ENTER to close the host"); Console.ReadLine(); host.Close(); } }- Proposed As Answer byHaripraghash Friday, November 06, 2009 1:28 AM
- I did not understand. Where do i need to it?Do I need to create a client and then generate the WSDl from that client?
Please give me all the steps expamles etc:
I neeed steps like , Create WCF service project, descrining the basics. - I wanted to understand one small thing.For asmx webservice, if we create an xsd, and use the xsd.exe tool it generated the class which we can use in the web service.
Is there any such utility for generating a class for WCF web services?
I mean any utility which will generate the class with the[System.Runtime.Serialization.DataMemberAttribute()] attribute for the corresponding XML?
Please let me know.Do I need to write the code explicitely for this? - Hi,
To generate proxy for WCF service you either use this tool called Svcutil.exe which can be found here
G:\Program Files\Microsoft SDKs\Windows\v6.0A\bin
Or
you can use "Add service reference" to generate the proxy class.
The following link has the details on how to create a WCF service
http://blogs.msdn.com/vbteam/archive/2007/08/30/A-Walkthrough-of-WCF-Support-in-Visual-Studio-2008.aspx
Once that is create you can use svcutil to generate the proxy class. The following link has step by step details one how to create the proxy class
http://msdn.microsoft.com/en-us/library/ms733133.aspx
Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/- Proposed As Answer byHaripraghash Friday, November 06, 2009 1:28 AM
- Hi,
In the sample given at http://blogs.msdn.com/vbteam/archive/2007/08/30/A-Walkthrough-of-WCF-Support-in-Visual-Studio-2008.aspx, I understood how to generate a proxy classes when I need to connect to the DB,
However In my case, i have the input and output complex xsd's which I want to convert to classes having the getter setter methods..
How Can I do that?I just need to create skeleton methods and generate wsdl file for the web service.I do not have to add any implementation to it at the moment.Please suggest. - Hi,
To generate the data contracts alone ie classes having getter and setter you can use the following command on svcutil. Svctuil is the utility you are looking for to generate classes from xsd files.
Go visual studio command prompt and type the following command. But replace the xsd name given below with the schema name.
svcutil.exe /dconly C:\schemaName.xsd -
Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/ Hi Hari,
This is my xsd:
<?xml version="1.0" encoding="utf-16" ?>
<xs:schema xmlns="http://TrustWCF.GetPolicyDetailResponse" targetNamespace="http://TrustWCF.GetPolicyDetailResponse" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="GetPolicyDetailResponse">
<xs:annotation>
<xs:appinfo>
<recordInfo rootTypeName="GetPolicyDetailResponse"/>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="PolicyNumber" type="xs:string" />
<xs:element name="Status" type="xs:string" />
<xs:element name="ProductCode" type="xs:string" />
<xs:element name="ProductDescription" type="xs:string" />
<xs:element name="EffectiveDate" type="xs:date" />
<xs:element name="ExpirationDate" type="xs:date" />
<xs:element name="PrimaryCoverageAmount1" type="xs:decimal" />
<xs:element name="PrimaryCoverageAmount2" type="xs:decimal" />
<xs:element name="WaitingPeriod" type="xs:int" />
<xs:element name="Mode" type="xs:string" />
<xs:element name="ModalPremium" type="xs:decimal" />
<xs:element name="RateClass" type="xs:string" />
<xs:element name="RateClassExpirationDate" type="xs:date" />
<xs:element name="WaiverOfContribution" type="xs:boolean" />
<xs:element name="ExpandedCoverage">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Coverage">
<xs:complexType>
<xs:sequence>
<xs:element name="Description" type="xs:string" />
<xs:element name="Included" type="xs:boolean" />
<xs:element name="CoverageAmount1" type="xs:decimal" />
<xs:element name="CoverageAmount2" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Assignee">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstName" type="xs:string" />
<xs:element name="MiddleInitial" type="xs:string" />
<xs:element name="LastName" type="xs:string" />
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element name="Type" type="xs:string" />
<xs:element name="CountryCode" type="xs:string" />
<xs:element name="CountryDescription" type="xs:string" />
<xs:element name="Street1" type="xs:string" />
<xs:element name="Street2" type="xs:string" />
<xs:element name="City" type="xs:string" />
<xs:element name="State" type="xs:string" />
<xs:element name="ZipCode" type="xs:string" />
<xs:element name="CountyCode" type="xs:string" />
<xs:element name="County" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="EmploymentDetail">
<xs:complexType>
<xs:sequence>
<xs:element name="EmploymentStatus" type="xs:string" />
<xs:element name="HourlyStatus" type="xs:string" />
<xs:element name="WorkEnvironmentCode" type="xs:int" />
<xs:element name="WorkEnvironmentDescription" type="xs:string" />
<xs:element name="AreaOfSpecialtyCode" type="xs:int" />
<xs:element name="AreaOfSpecialtyDescription" type="xs:string" />
<xs:element name="EmployerName" type="xs:string" />
<xs:element name="EmployerAddress">
<xs:complexType>
<xs:sequence>
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element name="Type" type="xs:string" />
<xs:element name="CountryCode" type="xs:string" />
<xs:element name="CountryDescription" type="xs:string" />
<xs:element name="Street1" type="xs:string" />
<xs:element name="Street2" type="xs:string" />
<xs:element name="City" type="xs:string" />
<xs:element name="State" type="xs:string" />
<xs:element name="ZipCode" type="xs:string" />
<xs:element name="CountyCode" type="xs:string" />
<xs:element name="County" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Professions">
<xs:complexType>
<xs:sequence>
<xs:element name="Profession">
<xs:complexType>
<xs:sequence>
<xs:element name="Type" type="xs:string" />
<xs:element name="ProfessionCode" type="xs:string" />
<xs:element name="ProfessionDescription" type="xs:string" />
<xs:element name="Level" type="xs:int" />
<xs:element name="LOB" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PaymentInfo">
<xs:complexType>
<xs:sequence>
<xs:element name="TotalBilled" type="xs:decimal" />
<xs:element name="RemainingBalance" type="xs:decimal" />
<xs:element name="LastPaymentDate" type="xs:date" />
<xs:element name="LastPaymentAmount" type="xs:decimal" />
<xs:element name="PaymentAmountDue" type="xs:decimal" />
<xs:element name="PaymentDueDate" type="xs:date" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Addresses">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Address">
<xs:complexType>
<xs:sequence>
<xs:element name="Type" type="xs:string" />
<xs:element name="CountryCode" type="xs:string" />
<xs:element name="CountryDescription" type="xs:string" />
<xs:element name="Street1" type="xs:string" />
<xs:element name="Street2" type="xs:string" />
<xs:element name="City" type="xs:string" />
<xs:element name="State" type="xs:string" />
<xs:element name="ZipCode" type="xs:string" />
<xs:element name="CountyCode" type="xs:string" />
<xs:element name="County" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I am using the svcutil command and I get the following errors.Please tell me what am i doing wrong here?
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin>svcutil.exe /dconly GetPolicyD
etailResponse.xsd
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.648]
Copyright (c) Microsoft Corporation. All rights reserved.Error: Type 'GetPolicyDetailResponse' in namespace 'http://TrustWCF.GetPolicyDet
ailResponse' cannot be imported. Form on element 'PolicyNumber' must be qualifie
d. Either change the schema so that the types can map to data contract types or
use ImportXmlType or use a different serializer.
If you are using the /dataContractOnly option to import data contract types and
are getting this error message, consider using xsd.exe instead. Types generated
by xsd.exe may be used in the Windows Communication Foundation after applying th
e XmlSerializerFormatAttribute attribute on your service contract. Alternatively
, consider using the /importXmlTypes option to import these types as XML types t
o use with DataContractFormatAttribute attribute on your service contract.- Hi,
I did a change to your schema as mandated by the datacontract serializer. I have added this elementFormDefault="qualified">
Switch -<xs:schema xmlns="http://TrustWCF.GetPolicyDetailResponse" targetNamespace="http://TrustWCF.GetPolicyDetailResponse" xmlns:xs="http://www.w3.org/2001/XMLSchema" <strong>elementFormDefault="qualified"</strong>> <xs:element name="GetPolicyDetailResponse"> <xs:annotation> <xs:appinfo> <recordInfo rootTypeName="GetPolicyDetailResponse"/> </xs:appinfo> </xs:annotation> <xs:complexType> <xs:sequence> <xs:element name="PolicyNumber" type="xs:string" /> <xs:element name="Status" type="xs:string" /> <xs:element name="ProductCode" type="xs:string" /> <xs:element name="ProductDescription" type="xs:string" /> <xs:element name="EffectiveDate" type="xs:date" /> <xs:element name="ExpirationDate" type="xs:date" /> <xs:element name="PrimaryCoverageAmount1" type="xs:decimal" /> <xs:element name="PrimaryCoverageAmount2" type="xs:decimal" /> <xs:element name="WaitingPeriod" type="xs:int" /> <xs:element name="Mode" type="xs:string" /> <xs:element name="ModalPremium" type="xs:decimal" /> <xs:element name="RateClass" type="xs:string" /> <xs:element name="RateClassExpirationDate" type="xs:date" /> <xs:element name="WaiverOfContribution" type="xs:boolean" /> <xs:element name="ExpandedCoverage"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" maxOccurs="unbounded" name="Coverage"> <xs:complexType> <xs:sequence> <xs:element name="Description" type="xs:string" /> <xs:element name="Included" type="xs:boolean" /> <xs:element name="CoverageAmount1" type="xs:decimal" /> <xs:element name="CoverageAmount2" type="xs:decimal" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Assignee"> <xs:complexType> <xs:sequence> <xs:element name="FirstName" type="xs:string" /> <xs:element name="MiddleInitial" type="xs:string" /> <xs:element name="LastName" type="xs:string" /> <xs:element name="Address"> <xs:complexType> <xs:sequence> <xs:element name="Type" type="xs:string" /> <xs:element name="CountryCode" type="xs:string" /> <xs:element name="CountryDescription" type="xs:string" /> <xs:element name="Street1" type="xs:string" /> <xs:element name="Street2" type="xs:string" /> <xs:element name="City" type="xs:string" /> <xs:element name="State" type="xs:string" /> <xs:element name="ZipCode" type="xs:string" /> <xs:element name="CountyCode" type="xs:string" /> <xs:element name="County" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="EmploymentDetail"> <xs:complexType> <xs:sequence> <xs:element name="EmploymentStatus" type="xs:string" /> <xs:element name="HourlyStatus" type="xs:string" /> <xs:element name="WorkEnvironmentCode" type="xs:int" /> <xs:element name="WorkEnvironmentDescription" type="xs:string" /> <xs:element name="AreaOfSpecialtyCode" type="xs:int" /> <xs:element name="AreaOfSpecialtyDescription" type="xs:string" /> <xs:element name="EmployerName" type="xs:string" /> <xs:element name="EmployerAddress"> <xs:complexType> <xs:sequence> <xs:element name="Address"> <xs:complexType> <xs:sequence> <xs:element name="Type" type="xs:string" /> <xs:element name="CountryCode" type="xs:string" /> <xs:element name="CountryDescription" type="xs:string" /> <xs:element name="Street1" type="xs:string" /> <xs:element name="Street2" type="xs:string" /> <xs:element name="City" type="xs:string" /> <xs:element name="State" type="xs:string" /> <xs:element name="ZipCode" type="xs:string" /> <xs:element name="CountyCode" type="xs:string" /> <xs:element name="County" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Professions"> <xs:complexType> <xs:sequence> <xs:element name="Profession"> <xs:complexType> <xs:sequence> <xs:element name="Type" type="xs:string" /> <xs:element name="ProfessionCode" type="xs:string" /> <xs:element name="ProfessionDescription" type="xs:string" /> <xs:element name="Level" type="xs:int" /> <xs:element name="LOB" type="xs:int" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="PaymentInfo"> <xs:complexType> <xs:sequence> <xs:element name="TotalBilled" type="xs:decimal" /> <xs:element name="RemainingBalance" type="xs:decimal" /> <xs:element name="LastPaymentDate" type="xs:date" /> <xs:element name="LastPaymentAmount" type="xs:decimal" /> <xs:element name="PaymentAmountDue" type="xs:decimal" /> <xs:element name="PaymentDueDate" type="xs:date" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="Addresses"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" maxOccurs="unbounded" name="Address"> <xs:complexType> <xs:sequence> <xs:element name="Type" type="xs:string" /> <xs:element name="CountryCode" type="xs:string" /> <xs:element name="CountryDescription" type="xs:string" /> <xs:element name="Street1" type="xs:string" /> <xs:element name="Street2" type="xs:string" /> <xs:element name="City" type="xs:string" /> <xs:element name="State" type="xs:string" /> <xs:element name="ZipCode" type="xs:string" /> <xs:element name="CountyCode" type="xs:string" /> <xs:element name="County" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
>svcutil /dataContractOnly c:\GetPolicyDetailResponse.xsd
Please refer to this to understand why that change was required
http://www.apexa.net/Blog/web_design_Blog_20080429.aspx
Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/- Proposed As Answer byHaripraghash Friday, November 06, 2009 6:05 AM
Hello Hari,
Thanks a lot for finding the time to change the xsd,the new xsd did work for me:
I have created a very small wcf web service app where I have converted 2 xsd to classes.The classes are
1; trustwcf.getpolicydetailresponse.GetPolicyDetailResponse
2:GetPolicyDetailRequest
Now , in my Web service site, I have the following code:
IService.cs
-------------------
[
ServiceContract]
public
interface IService
{
// TODO: Add your service operations here
//INSERT DATA OPERATIONS
[
OperationContract(IsOneWay = false)]
[
WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "getpolicydetailRequest")]
trustwcf.getpolicydetailresponse.
GetPolicyDetailResponse getPolicyDetailRequest(GetPolicyDetailRequest getPolicyDetailRequestxml);
}
in Service.cs, I am just creating a skeleton of the class, with no functionality
[
ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, AddressFilterMode = AddressFilterMode.Any)]
public
class Service : IService
{
public trustwcf.getpolicydetailresponse.GetPolicyDetailResponse getPolicyDetailRequest(GetPolicyDetailRequest getPolicyDetailRequestxml)
{
trustwcf.getpolicydetailresponse.
GetPolicyDetailResponse xmlresponse = new trustwcf.getpolicydetailresponse.GetPolicyDetailResponse();
return xmlresponse;
}
When I browse the service.svc in browser, I get the following error:
Compiler Error Message: CS0102: The type 'NewDataSet' already contains a definition for '_schemaSerializationMode'
I am stuck and need to get it done urgently.
Please could you take a look.I can send you the small application I have created if you want.
As mentioned earlier , all I want now are skeleton classes just for generating the wsdl.
Please respond and help.- Hi,
Can you upload your sample along with the xsds somewhere and post the link
Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/ - Hello Hari,
I have uploaded the file at http://www.box.net/shared/i69hzharzt
Please take a look whenever you can
If you are not able to access this file,Please send a mail to my email ID and I will send you the application.There is really not much in it, but I am not able to figure out.I will be waiting for your response.- Edited byRachanaD Saturday, November 07, 2009 11:25 AM
- Hi Rachana,
I have re generated the contracts and have a made a project for that. I have uploaded your sample in the following location.
http://cid-05c2e50f2c5140c1.skydrive.live.com/self.aspx/.Public/WcfService4.rar
Let me if it helps.
Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/- Marked As Answer byRachanaD Sunday, November 08, 2009 3:50 AM
- Thanks Hari.It is working.
If you dont mind could you tell me what changes you did.
I saw that there were no changes to service.svc or to IService so I am assuming that you changed just the Contracts.
Did you regenerate it using svcutil.exe or using xsd.exe and then modified it manually.
Please let me know.It will help me in creating the contracts for my other web methods.. - Hi Rachana,
i just used >svcutil /dataContractOnly c:\GetPolicyDetailResponse.xsd to generate the contracts. thats all i did. the contracts you generated had datasets in them. i am not how generated(may be thru xsd.exe?). all i did was to use >svcutil /dataContractOnly c:\GetPolicyDetailResponse.xsd and generate contracts. you can try it as well
Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/- Marked As Answer byRachanaD Sunday, November 08, 2009 3:51 AM
- Thanks Hari.It is working.Thanks a lot for your help.
- You are welcome :)
Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. http://thoughtorientedarchitecture.blogspot.com/


