Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从URL调用WCF服务时未找到WCF终结点_C#_.net_Wcf - Fatal编程技术网

C# 从URL调用WCF服务时未找到WCF终结点

C# 从URL调用WCF服务时未找到WCF终结点,c#,.net,wcf,C#,.net,Wcf,我创建了WCF服务。我创建了两个普通的方法,它们是非参数方法。但是我创建了一个新方法,但是这次它需要两个参数。方法如下 界面: [OperationContract] [WebInvoke(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetClassCode/{name}/{password}")] int GetAuthenticatedUse

我创建了WCF服务。我创建了两个普通的方法,它们是非参数方法。但是我创建了一个新方法,但是这次它需要两个参数。方法如下

界面:

[OperationContract]     
[WebInvoke(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetClassCode/{name}/{password}")]
int GetAuthenticatedUserData(string name, string password);
.Cs

 public int GetAuthenticatedUserData(string name, string password)
    {
        try
        {
            DataTable dt = new DataTable();
            using (SqlConnection con = new SqlConnection(@"Data Source=HITSEDGE\HITSEDGE;Initial Catalog=CCIL1;User ID=dbassist;Password=assist@123"))
            {
                using (SqlCommand cmd = new SqlCommand("SELECT Name,Password from dbo.[CCIL$ADCS User] where Name=" + name + " and password" + password, con))
                {
                    con.Open();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(dt);
                    if (dt != null)
                    {
                        return 1;
                    }
                    else
                        return 0;
                }
            }

        }
        catch (Exception)
        {

            throw;
        }



    }
我的web.config就像

    <?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <!--<basicHttpBinding>
        <binding name="NewBinding0" />
      </basicHttpBinding>-->
      <basicHttpBinding>
        <binding name="ExtendedMaxSize"
            maxBufferSize="999999" maxReceivedMessageSize="999999" />
      </basicHttpBinding>
      <webHttpBinding>
        <binding name="crossDomain" crossDomainScriptAccessEnabled="true"></binding>
      </webHttpBinding>

    </bindings>
    <services>
      <!--<service name="MyService.MyService">
        <endpoint address="mex" binding="basicHttpBinding"
          bindingConfiguration="NewBinding0" contract="MyService.IMyService" />
      </service>-->

      <service name="MyService.MyService" behaviorConfiguration="DefaultBehavior">
        <endpoint address="" binding="webHttpBinding" contract="MyService.IMyService" name="MyService.MyService" behaviorConfiguration="AjaxBehavior"  bindingConfiguration="crossDomain">

          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>


      </service>
    </services>
    <behaviors>

      <serviceBehaviors>
        <behavior name="DefaultBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="AjaxBehavior">
          <webHttp></webHttp>
          <!--<webHttp helpEnabled="true" />-->
        </behavior>
      </endpointBehaviors>

      <!--<serviceBehaviors>
        <behavior>
          -->
      <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
      <!--
          <serviceMetadata httpGetEnabled="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>
    <serviceHostingEnvironment 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>

</configuration>

但当我通过URL调用我的参数方法时,比如下面的URL,我得到了错误未找到端点。

URL

Localhost/MyService.svc/GetAuthenticatedUserData?name='Himansu'&password='0hits@123"


请帮助我创建终点…

原因是您在方法上指定了以下属性:

UriTemplate = "GetClassCode/{name}/{password}"
这意味着您的端点URL实际上是:

http://localhost/MyService.svc/GetClassCode/Himansu/hits@123
最好不要将用户名和密码作为URL的一部分,而只是将它们作为querystring参数。因此,您可以只获得以下内容:

UriTemplate = "GetAuthenticatedUserData"

您的用户名和密码将使用querystring参数以相同的方式传递。

您是否在IIS上启用了HTTP服务激活?