我没有在app.config文件的用户界面(winforms)中获得终点信息
我添加了这样的服务引用,右键单击项目名称 - 添加 - 添加服务引用 - http://localhost:2850/TechpalleNew/Skillgun_App.svc-GO-OK 我的用户界面app.config文件就像这样
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings />
<client />
</system.serviceModel>
</configuration>
我尝试使用svcutil工具使用visual studio命令提示符,即时获取错误,因为访问路径被拒绝
C:\ProgramFiles\Microsoft Visual Studio 10.0\VC>svcutil.exe http://localhost:2850/TechpalleNew/Skillgun_App.svc?wsdl
我的wsdl代码
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Skillgun_App" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<xs:import namespace="http://schemas.datacontract.org/2004/07/Skillgun"/>
<xs:element name="Chapters_Names">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="sub_topic_id" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Chapters_NamesResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/Skillgun" minOccurs="0" name="Chapters_NamesResult" nillable="true" type="q1:ArrayOfChapterNames"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Paper_ids">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="chapter_id" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Paper_idsResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q2="http://schemas.datacontract.org/2004/07/Skillgun" minOccurs="0" name="Paper_idsResult" nillable="true" type="q2:ArrayOfPaper_Ids"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Qtions_data">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="paper_id" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Qtions_dataResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q3="http://schemas.datacontract.org/2004/07/Skillgun" minOccurs="0" name="Qtions_dataResult" nillable="true" type="q3:ArrayOfQtions_data"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:element name="anyType" nillable="true" type="xs:anyType"/>
<xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary"/>
<xs:element name="boolean" nillable="true" type="xs:boolean"/>
<xs:element name="byte" nillable="true" type="xs:byte"/>
<xs:element name="dateTime" nillable="true" type="xs:dateTime"/>
<xs:element name="decimal" nillable="true" type="xs:decimal"/>
<xs:element name="double" nillable="true" type="xs:double"/>
<xs:element name="float" nillable="true" type="xs:float"/>
<xs:element name="int" nillable="true" type="xs:int"/>
<xs:element name="long" nillable="true" type="xs:long"/>
<xs:element name="QName" nillable="true" type="xs:QName"/>
<xs:element name="short" nillable="true" type="xs:short"/>
<xs:element name="string" nillable="true" type="xs:string"/>
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte"/>
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt"/>
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong"/>
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort"/>
<xs:element name="char" nillable="true" type="tns:char"/>
<xs:simpleType name="char">
<xs:restriction base="xs:int"/>
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration"/>
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>
<xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>
<xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid"/>
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}- [\da-fA-F]{12}"/>
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName"/>
<xs:attribute name="Id" type="xs:ID"/>
<xs:attribute name="Ref" type="xs:IDREF"/>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/Skillgun" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/Skillgun">
<xs:complexType name="ArrayOfChapterNames">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="ChapterNames" nillable="true" type="tns:ChapterNames"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfChapterNames" nillable="true" type="tns:ArrayOfChapterNames"/>
<xs:complexType name="ChapterNames">
<xs:sequence>
<xs:element minOccurs="0" name="Qbc_id" type="xs:int"/>
<xs:element minOccurs="0" name="Qbc_nameofChapter" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Qbc_no_of_papers" type="xs:int"/>
<xs:element minOccurs="0" name="Qbc_no_of_questions" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ChapterNames" nillable="true" type="tns:ChapterNames"/>
<xs:complexType name="ArrayOfPaper_Ids">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Paper_Ids" nillable="true" type="tns:Paper_Ids"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfPaper_Ids" nillable="true" type="tns:ArrayOfPaper_Ids"/>
<xs:complexType name="Paper_Ids">
<xs:sequence>
<xs:element minOccurs="0" name="Paper_Id" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Paper_Ids" nillable="true" type="tns:Paper_Ids"/>
<xs:complexType name="ArrayOfQtions_data">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Qtions_data" nillable="true" type="tns:Qtions_data"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfQtions_data" nillable="true" type="tns:ArrayOfQtions_data"/>
<xs:complexType name="Qtions_data">
<xs:sequence>
<xs:element minOccurs="0" name="Answer" nillable="true" type="tns:ArrayOfAnswers"/>
<xs:element minOccurs="0" name="Q_answer_choice" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Q_answer_explaination" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Q_desc" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Q_help_text" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Q_id" type="xs:int"/>
<xs:element minOccurs="0" name="Qbt_hint_for_complete_chapter" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Qtions_data" nillable="true" type="tns:Qtions_data"/>
<xs:complexType name="ArrayOfAnswers">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Answers" nillable="true" type="tns:Answers"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfAnswers" nillable="true" type="tns:ArrayOfAnswers"/>
<xs:complexType name="Answers">
<xs:sequence>
<xs:element minOccurs="0" name="Choice" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Answers" nillable="true" type="tns:Answers"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="ISkillgun_App_Chapters_Names_InputMessage">
<wsdl:part name="parameters" element="tns:Chapters_Names"/>
</wsdl:message>
<wsdl:message name="ISkillgun_App_Chapters_Names_OutputMessage">
<wsdl:part name="parameters" element="tns:Chapters_NamesResponse"/>
</wsdl:message>
<wsdl:message name="ISkillgun_App_Paper_ids_InputMessage">
<wsdl:part name="parameters" element="tns:Paper_ids"/>
</wsdl:message>
<wsdl:message name="ISkillgun_App_Paper_ids_OutputMessage">
<wsdl:part name="parameters" element="tns:Paper_idsResponse"/>
</wsdl:message>
<wsdl:message name="ISkillgun_App_Qtions_data_InputMessage">
<wsdl:part name="parameters" element="tns:Qtions_data"/>
</wsdl:message>
<wsdl:message name="ISkillgun_App_Qtions_data_OutputMessage">
<wsdl:part name="parameters" element="tns:Qtions_dataResponse"/>
</wsdl:message>
<wsdl:portType name="ISkillgun_App">
<wsdl:operation name="Chapters_Names">
<wsdl:input wsaw:Action="http://tempuri.org/ISkillgun_App/Chapters_Names" message="tns:ISkillgun_App_Chapters_Names_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ISkillgun_App/Chapters_NamesResponse" message="tns:ISkillgun_App_Chapters_Names_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="Paper_ids">
<wsdl:input wsaw:Action="http://tempuri.org/ISkillgun_App/Paper_ids" message="tns:ISkillgun_App_Paper_ids_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ISkillgun_App/Paper_idsResponse" message="tns:ISkillgun_App_Paper_ids_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="Qtions_data">
<wsdl:input wsaw:Action="http://tempuri.org/ISkillgun_App/Qtions_data" message="tns:ISkillgun_App_Qtions_data_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ISkillgun_App/Qtions_dataResponse" message="tns:ISkillgun_App_Qtions_data_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:service name="Skillgun_App"/>
</wsdl:definitions>
我的svc代码
namespace Skillgun
{
[ServiceContract]
public interface ISkillgun_App
{
[OperationContract]
[System.ServiceModel.Web.WebInvoke(Method = "GET", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped, UriTemplate = "mobile/chapters/{sub_topic_id}/app")]
List<ChapterNames> Chapters_Names(string sub_topic_id);
[OperationContract]
[System.ServiceModel.Web.WebInvoke(Method = "GET", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped, UriTemplate = "mobile/papers/{chapter_id}/app")]
List<Paper_Ids> Paper_ids(string chapter_id);
[OperationContract]
[System.ServiceModel.Web.WebInvoke(Method = "GET", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.Wrapped, UriTemplate = "mobile/questions/{paper_id}/app")]
List<Qtions_data> Qtions_data(string paper_id);
}
}
namespace Skillgun
{
public class Service1 : ISkillgun_App
{
private string strConnection = .....
public List<ChapterNames> Chapters_Names(string sub_topic_id)
{
List<ChapterNames> chptrsdetails = new List<ChapterNames>();
using (SqlConnection cn = new SqlConnection(strConnection))
{
using (SqlCommand cmd = new SqlCommand("skillgun_mobile_app_Qtions_data", cn))
{
cmd.CommandType = CommandType.StoredProcedure;
try
{
SqlParameter p1 = new SqlParameter("@type", SqlDbType.VarChar, 20);
SqlParameter p2 = new SqlParameter("@topic_or_paper_id", SqlDbType.Int);
p1.Value = "chapters_data";
p2.Value = sub_topic_id;
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add("@username", SqlDbType.VarChar, 40);
cmd.Parameters["@username"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@password", SqlDbType.VarChar, 40);
cmd.Parameters["@password"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@package_name", SqlDbType.VarChar, 50);
cmd.Parameters["@package_name"].Direction = ParameterDirection.Output;
cn.Open();
SqlDataReader drtopics = cmd.ExecuteReader();
while (drtopics.Read())
{
ChapterNames qbsubchapter = new ChapterNames();
qbsubchapter.Qbc_id = (int)drtopics["qbc_id"];
qbsubchapter.Qbc_nameofChapter = drtopics["qbc_nameofChapter"].ToString();
qbsubchapter.Qbc_no_of_papers = (int)drtopics["qbc_no_of_papers"];
qbsubchapter.Qbc_no_of_questions = (int)drtopics["qbc_no_of_questions"];
chptrsdetails.Add(qbsubchapter);
}
drtopics.Close();
cn.Close();
string topic_username = cmd.Parameters["@username"].Value.ToString();
string topic_password = cmd.Parameters["@password"].Value.ToString();
string topic_package_name = cmd.Parameters["@package_name"].Value.ToString();
bool result = check_user(topic_username, topic_password, topic_package_name);
if (result == true)
return chptrsdetails;
else
return null;
}
catch (SqlException ex)
{
return null;
}
finally
{
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
}
}
}
}
类似于剩余的2种方法
答案 0 :(得分:0)
使用以下代码创建您的wcf服务。
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Skillgun
{
using System.Runtime.Serialization;
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="ChapterNames", Namespace="http://schemas.datacontract.org/2004/07/Skillgun")]
public partial class ChapterNames : object, System.Runtime.Serialization.IExtensibleDataObject
{
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
private int Qbc_idField;
private string Qbc_nameofChapterField;
private int Qbc_no_of_papersField;
private int Qbc_no_of_questionsField;
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int Qbc_id
{
get
{
return this.Qbc_idField;
}
set
{
this.Qbc_idField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Qbc_nameofChapter
{
get
{
return this.Qbc_nameofChapterField;
}
set
{
this.Qbc_nameofChapterField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int Qbc_no_of_papers
{
get
{
return this.Qbc_no_of_papersField;
}
set
{
this.Qbc_no_of_papersField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int Qbc_no_of_questions
{
get
{
return this.Qbc_no_of_questionsField;
}
set
{
this.Qbc_no_of_questionsField = value;
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Paper_Ids", Namespace="http://schemas.datacontract.org/2004/07/Skillgun")]
public partial class Paper_Ids : object, System.Runtime.Serialization.IExtensibleDataObject
{
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
private int Paper_IdField;
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int Paper_Id
{
get
{
return this.Paper_IdField;
}
set
{
this.Paper_IdField = value;
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Qtions_data", Namespace="http://schemas.datacontract.org/2004/07/Skillgun")]
public partial class Qtions_data : object, System.Runtime.Serialization.IExtensibleDataObject
{
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
private Skillgun.Answers[] AnswerField;
private string Q_answer_choiceField;
private string Q_answer_explainationField;
private string Q_descField;
private string Q_help_textField;
private int Q_idField;
private string Qbt_hint_for_complete_chapterField;
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Skillgun.Answers[] Answer
{
get
{
return this.AnswerField;
}
set
{
this.AnswerField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Q_answer_choice
{
get
{
return this.Q_answer_choiceField;
}
set
{
this.Q_answer_choiceField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Q_answer_explaination
{
get
{
return this.Q_answer_explainationField;
}
set
{
this.Q_answer_explainationField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Q_desc
{
get
{
return this.Q_descField;
}
set
{
this.Q_descField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Q_help_text
{
get
{
return this.Q_help_textField;
}
set
{
this.Q_help_textField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int Q_id
{
get
{
return this.Q_idField;
}
set
{
this.Q_idField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Qbt_hint_for_complete_chapter
{
get
{
return this.Qbt_hint_for_complete_chapterField;
}
set
{
this.Qbt_hint_for_complete_chapterField = value;
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="Answers", Namespace="http://schemas.datacontract.org/2004/07/Skillgun")]
public partial class Answers : object, System.Runtime.Serialization.IExtensibleDataObject
{
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
private string ChoiceField;
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Choice
{
get
{
return this.ChoiceField;
}
set
{
this.ChoiceField = value;
}
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="ISkillgun_App")]
public interface ISkillgun_App
{
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISkillgun_App/Chapters_Names", ReplyAction="http://tempuri.org/ISkillgun_App/Chapters_NamesResponse")]
Skillgun.ChapterNames[] Chapters_Names(string sub_topic_id);
//[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISkillgun_App/Chapters_Names", ReplyAction="http://tempuri.org/ISkillgun_App/Chapters_NamesResponse")]
//System.Threading.Tasks.Task<Skillgun.ChapterNames[]> Chapters_NamesAsync(string sub_topic_id);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISkillgun_App/Paper_ids", ReplyAction="http://tempuri.org/ISkillgun_App/Paper_idsResponse")]
Skillgun.Paper_Ids[] Paper_ids(string chapter_id);
//[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISkillgun_App/Paper_ids", ReplyAction="http://tempuri.org/ISkillgun_App/Paper_idsResponse")]
//System.Threading.Tasks.Task<Skillgun.Paper_Ids[]> Paper_idsAsync(string chapter_id);
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISkillgun_App/Qtions_data", ReplyAction="http://tempuri.org/ISkillgun_App/Qtions_dataResponse")]
Skillgun.Qtions_data[] Qtions_data(string paper_id);
//[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ISkillgun_App/Qtions_data", ReplyAction="http://tempuri.org/ISkillgun_App/Qtions_dataResponse")]
//System.Threading.Tasks.Task<Skillgun.Qtions_data[]> Qtions_dataAsync(string paper_id);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface ISkillgun_AppChannel : ISkillgun_App, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class Skillgun_AppClient : System.ServiceModel.ClientBase<ISkillgun_App>, ISkillgun_App
{
public Skillgun_AppClient()
{
}
public Skillgun_AppClient(string endpointConfigurationName) :
base(endpointConfigurationName)
{
}
public Skillgun_AppClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public Skillgun_AppClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public Skillgun_AppClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
public Skillgun.ChapterNames[] Chapters_Names(string sub_topic_id)
{
return base.Channel.Chapters_Names(sub_topic_id);
}
public Skillgun.Paper_Ids[] Paper_ids(string chapter_id)
{
return base.Channel.Paper_ids(chapter_id);
}
public Skillgun.Qtions_data[] Qtions_data(string paper_id)
{
return base.Channel.Qtions_data(paper_id);
}
}
svc应该如下所示。
using System;
using Skillgun;
namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class Skillgun_App : ISkillgun_App
{
public ChapterNames[] Chapters_Names(string sub_topic_id)
{
throw new NotImplementedException();
}
public Paper_Ids[] Paper_ids(string chapter_id)
{
throw new NotImplementedException();
}
public Qtions_data[] Qtions_data(string paper_id)
{
throw new NotImplementedException();
}
}
}
完成后,运行您的服务并转到wsdl。它应该如下所示。
<wsdl:definitions name="Skillgun_App" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.datacontract.org/2004/07/Skillgun"/>
<xs:element name="Chapters_Names">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="sub_topic_id" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Chapters_NamesResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="Chapters_NamesResult" nillable="true" type="q1:ArrayOfChapterNames" xmlns:q1="http://schemas.datacontract.org/2004/07/Skillgun"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Paper_ids">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="chapter_id" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Paper_idsResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="Paper_idsResult" nillable="true" type="q2:ArrayOfPaper_Ids" xmlns:q2="http://schemas.datacontract.org/2004/07/Skillgun"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Qtions_data">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="paper_id" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Qtions_dataResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="Qtions_dataResult" nillable="true" type="q3:ArrayOfQtions_data" xmlns:q3="http://schemas.datacontract.org/2004/07/Skillgun"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:element name="anyType" nillable="true" type="xs:anyType"/>
<xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary"/>
<xs:element name="boolean" nillable="true" type="xs:boolean"/>
<xs:element name="byte" nillable="true" type="xs:byte"/>
<xs:element name="dateTime" nillable="true" type="xs:dateTime"/>
<xs:element name="decimal" nillable="true" type="xs:decimal"/>
<xs:element name="double" nillable="true" type="xs:double"/>
<xs:element name="float" nillable="true" type="xs:float"/>
<xs:element name="int" nillable="true" type="xs:int"/>
<xs:element name="long" nillable="true" type="xs:long"/>
<xs:element name="QName" nillable="true" type="xs:QName"/>
<xs:element name="short" nillable="true" type="xs:short"/>
<xs:element name="string" nillable="true" type="xs:string"/>
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte"/>
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt"/>
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong"/>
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort"/>
<xs:element name="char" nillable="true" type="tns:char"/>
<xs:simpleType name="char">
<xs:restriction base="xs:int"/>
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration"/>
<xs:simpleType name="duration">
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>
<xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>
<xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid"/>
<xs:simpleType name="guid">
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/>
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName"/>
<xs:attribute name="Id" type="xs:ID"/>
<xs:attribute name="Ref" type="xs:IDREF"/>
</xs:schema>
<xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/Skillgun" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/Skillgun">
<xs:complexType name="ArrayOfChapterNames">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="ChapterNames" nillable="true" type="tns:ChapterNames"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfChapterNames" nillable="true" type="tns:ArrayOfChapterNames"/>
<xs:complexType name="ChapterNames">
<xs:sequence>
<xs:element minOccurs="0" name="Qbc_id" type="xs:int"/>
<xs:element minOccurs="0" name="Qbc_nameofChapter" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Qbc_no_of_papers" type="xs:int"/>
<xs:element minOccurs="0" name="Qbc_no_of_questions" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ChapterNames" nillable="true" type="tns:ChapterNames"/>
<xs:complexType name="ArrayOfPaper_Ids">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Paper_Ids" nillable="true" type="tns:Paper_Ids"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfPaper_Ids" nillable="true" type="tns:ArrayOfPaper_Ids"/>
<xs:complexType name="Paper_Ids">
<xs:sequence>
<xs:element minOccurs="0" name="Paper_Id" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Paper_Ids" nillable="true" type="tns:Paper_Ids"/>
<xs:complexType name="ArrayOfQtions_data">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Qtions_data" nillable="true" type="tns:Qtions_data"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfQtions_data" nillable="true" type="tns:ArrayOfQtions_data"/>
<xs:complexType name="Qtions_data">
<xs:sequence>
<xs:element minOccurs="0" name="Answer" nillable="true" type="tns:ArrayOfAnswers"/>
<xs:element minOccurs="0" name="Q_answer_choice" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Q_answer_explaination" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Q_desc" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Q_help_text" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Q_id" type="xs:int"/>
<xs:element minOccurs="0" name="Qbt_hint_for_complete_chapter" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Qtions_data" nillable="true" type="tns:Qtions_data"/>
<xs:complexType name="ArrayOfAnswers">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Answers" nillable="true" type="tns:Answers"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfAnswers" nillable="true" type="tns:ArrayOfAnswers"/>
<xs:complexType name="Answers">
<xs:sequence>
<xs:element minOccurs="0" name="Choice" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Answers" nillable="true" type="tns:Answers"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="ISkillgun_App_Chapters_Names_InputMessage">
<wsdl:part name="parameters" element="tns:Chapters_Names"/>
</wsdl:message>
<wsdl:message name="ISkillgun_App_Chapters_Names_OutputMessage">
<wsdl:part name="parameters" element="tns:Chapters_NamesResponse"/>
</wsdl:message>
<wsdl:message name="ISkillgun_App_Paper_ids_InputMessage">
<wsdl:part name="parameters" element="tns:Paper_ids"/>
</wsdl:message>
<wsdl:message name="ISkillgun_App_Paper_ids_OutputMessage">
<wsdl:part name="parameters" element="tns:Paper_idsResponse"/>
</wsdl:message>
<wsdl:message name="ISkillgun_App_Qtions_data_InputMessage">
<wsdl:part name="parameters" element="tns:Qtions_data"/>
</wsdl:message>
<wsdl:message name="ISkillgun_App_Qtions_data_OutputMessage">
<wsdl:part name="parameters" element="tns:Qtions_dataResponse"/>
</wsdl:message>
<wsdl:portType name="ISkillgun_App">
<wsdl:operation name="Chapters_Names">
<wsdl:input wsaw:Action="http://tempuri.org/ISkillgun_App/Chapters_Names" message="tns:ISkillgun_App_Chapters_Names_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ISkillgun_App/Chapters_NamesResponse" message="tns:ISkillgun_App_Chapters_Names_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="Paper_ids">
<wsdl:input wsaw:Action="http://tempuri.org/ISkillgun_App/Paper_ids" message="tns:ISkillgun_App_Paper_ids_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ISkillgun_App/Paper_idsResponse" message="tns:ISkillgun_App_Paper_ids_OutputMessage"/>
</wsdl:operation>
<wsdl:operation name="Qtions_data">
<wsdl:input wsaw:Action="http://tempuri.org/ISkillgun_App/Qtions_data" message="tns:ISkillgun_App_Qtions_data_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ISkillgun_App/Qtions_dataResponse" message="tns:ISkillgun_App_Qtions_data_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_ISkillgun_App" type="tns:ISkillgun_App">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Chapters_Names">
<soap:operation soapAction="http://tempuri.org/ISkillgun_App/Chapters_Names" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="Paper_ids">
<soap:operation soapAction="http://tempuri.org/ISkillgun_App/Paper_ids" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="Qtions_data">
<soap:operation soapAction="http://tempuri.org/ISkillgun_App/Qtions_data" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Skillgun_App">
<wsdl:port name="BasicHttpBinding_ISkillgun_App" binding="tns:BasicHttpBinding_ISkillgun_App">
<soap:address location="http://localhost:65100/Skillgun_App.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Web配置..
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
答案 1 :(得分:0)
您应该有一个Web.config文件,其中必须设置与默认端点相关的正确绑定信息。为了方便起见,Visual Studio在WCF下附带了一个项目模板 - &gt; WCF服务应用程序。使用它可以避免遗漏任何可能导致您在问题中说明的问题的配置步骤。您只能专注于合同实施,其余的工作将由您负责。创建此类型的项目后,您可以在解决方案资源管理器中看到3个重要文件。 IService.cs文件,您将在其中放置合同定义和实现,然后是Service.svc文件,该文件应该启动IIS中托管的服务和Web.Config文件。您的工作只是更新IService.cs文件。
然后,您可以在具有此WCF服务项目的同一解决方案下添加Windows窗体应用程序项目,然后通过发现服务添加对此WinForms项目的服务引用,如下所示:
确保您的App.Config文件具有所需的端点配置,如下所示:
这就是全部。你不能在这种方法中遇到任何问题。
[注意:添加服务引用时尝试使用Discover选项,以便我们避免在键入服务URL时可能出现的任何错误。]