简体   繁体   English

关于wcf服务的端点信息的问题

[英]Issues on End point information of wcf services

I'm not getting end point information in the user interface(winforms) of app.config file 我没有在app.config文件的用户界面(winforms)中获得端点信息

i added service reference like this right-click on the project name-Add-Add Service Reference- http://localhost:2850/TechpalleNew/Skillgun_App.svc-GO-OK my user interface app.config file came like this 我添加了这样的服务引用,右键单击项目名称-添加-添加服务引用-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> 

I tried with svcutil tool using visual studio command prompt ,im getting the error as Access to the path is denied 我尝试使用Visual Studio命令提示符使用svcutil工具,但由于拒绝访问路径而收到错误

C:\ProgramFiles\Microsoft Visual Studio 10.0\VC>svcutil.exe http://localhost:2850/TechpalleNew/Skillgun_App.svc?wsdl

My wsdl code 我的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>

My svc code 我的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();
                    }
                }
            }
        }
    }

similar for remaining 2 methods 其余2种方法相似

在此处输入图片说明 这就是您的app.config的外观。 Your wsdl is not correct. 您的wsdl不正确。

Use below code to create your wcf service. 使用以下代码创建您的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);
    }

}

The svc should look like below. 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();
        }
    }
}

Once that's done, run your service and go to wsdl. 完成后,运行您的服务并转到wsdl。 It should look like below. 它应如下所示。

<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 Config.. 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>

You should have had a Web.config file where the right binding information related to the default endpoint must be set. 您应该有一个Web.config文件,其中必须设置与默认端点相关的正确绑定信息。 To make things easy Visual studio comes with a project template under WCF-> WCF Service Application. 为了使事情变得容易,Visual Studio在WCF-> WCF Service Application下提供了一个项目模板。 Use it to avoid missing any configuration steps that could lead to the problem you have stated in your question. 使用它来避免丢失任何可能导致问题中提到的问题的配置步骤。 You can focus only on your contract implementation and the rest is taken care of. 您只能专注于合同的执行,其余的工作都将得到处理。 Once a project of this type is created then you can see 3 important files in your Solution explorer. 创建此类型的项目后,您可以在解决方案资源管理器中看到3个重要文件。 The IService.cs file where you will put your contract definition and implementation, then the Service.svc file which should bring up the service hosted in IIS and the Web.Config file. IService.cs文件将在其中放置合同定义和实现,然后是Service.svc文件,该文件应调出IIS中托管的服务和Web.Config文件。 Your work would be to update the IService.cs file ONLY. 您的工作将只是更新IService.cs文件。

在此处输入图片说明

Then you can add a Windows Form application project under the same solution where you have this WCF service project and then add a service reference to this WinForms project by discovering the service as is shown below: 然后,您可以在具有该WCF服务项目的相同解决方案下添加Windows窗体应用程序项目,然后通过发现该服务来添加对该WinForms项目的服务引用,如下所示:

在此处输入图片说明

Here for sure your App.Config file will have the required endpoint configurations as shown below: 在此确保您的App.Config文件将具有所需的端点配置,如下所示:

在此处输入图片说明

That's all. 就这样。 You must not be facing any issues in this approach. 您一定不会在这种方法中遇到任何问题。

[NOTE: While adding the service reference try to use the Discover option so that we avoid any mistakes that might creep in while typing the service URL.] [注意:在添加服务引用时,请尝试使用“发现”选项,以避免在键入服务URL时可能出现的任何错误。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM