简体   繁体   English

如何在c#中的wcf服务中创建登录页面的获取和发布方法

[英]How Create Get and Post Methods for the Login Page in wcf service in c#

I am creating a WCF service in ASP.NET and there i need to implement Get and Post Methods for simple Login page 我在ASP.NET中创建一个WCF服务,我需要为简单的登录页面实现Get和Post Methods

This is for running the application on Local host.I have SQL server for the database. 这是为了在本地主机上运行应用程序。我有数据库的SQL服务器。

C#: This is the interface I have coded: C#:这是我编码的接口:

 [ServiceContract]
       public interface ILogin
        {
            [OperationContract(Name = "PostUserDetails")]
            [WebInvoke(Method = "POST",UriTemplate = "")]

            string UserName(Stream data);
            string UserPassword(Stream data);

            [OperationContract(Name = "GetUserDetails")]
            [WebGet(UriTemplate = "GetUserDetails/inputStr/{name}")]
            string UserName(string name);
            string UserPassword(string name);
        }

This is the class I have coded: 这是我编写的类:

public class Login :ILogin
    {
        public string UserName(Stream data)
        {
            StreamReader streamReader = new StreamReader(data);
            string xmlString = streamReader.ReadToEnd();
            string returnValue = xmlString;

            return returnValue;
        }

        public string UserPassword(Stream data)
        {
            StreamReader streamReader = new StreamReader(data);
            string xmlString = streamReader.ReadToEnd();
            string returnValue = xmlString;

            return returnValue;
        }

        public string UserName(string strUserName)
        {
            StringBuilder strReturnValue = new StringBuilder();
            // return username prefixed as shown below
            strReturnValue.Append(string.Format("You have entered userName as {0}", strUserName));
            return strReturnValue.ToString();
        }

        public string UserPassword(string strUserName)
        {
            StringBuilder strReturnValue = new StringBuilder();
            // return username prefixed as shown below
            strReturnValue.Append(string.Format("You have entered userName as {0}", strUserName));
            return strReturnValue.ToString();
        }
    }

I have also configured the web.config as: 我还将web.config配置为:

<system.serviceModel>
    <services>
      <service name="MyWCFService.Login" behaviourConfiguration ="loginbehaviour" >
        <endpoint name="webHttpBinding" address="" binding="webHttpBinding" contract="MyWCFService.ILogin" behaviorConfiguration="webHttp">
        </endpoint>
        <endpoint name ="mexHttpBinding" address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyWCFServiceBehaviour">
          <serviceMetadata httpGetEnabled="false"></serviceMetadata>
          <serviceDebug includeExceptionDetailInFaults="false"/>

          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webHttp"></behavior>
        <webHttp/>
      </endpointBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

I am getting HTTP Error 404.7 - Not Found Error 我收到HTTP错误404.7 - 未找到错误

First of all you cant use Stream as your input. 首先,你不能使用Stream作为输入。 because stream con not serialized. 因为stream con没有序列化。 then you don't need to create two separate methods. 那么你不需要创建两个单独的方法。 create login like this and use * as your Method. 像这样创建登录并使用*作为您的方法。 something like this: 这样的事情:

    [OperationContract(Name = "PostUserDetails")]
    [WebInvoke(Method = "*",UriTemplate = "")]

    string UserName(Data data);
    string UserPassword(Data data);

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

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