端点从同一服务运行特定方法时找不到

时间:2018-01-03 19:12:52

标签: c# wcf

所有我试图运行WCF服务,但当我尝试调用特定的服务方法时,我收到错误

  

未找到端点

在第三方托管服务器上托管后。

这是我的.SVC.cs代码

public class AUTOHUBWITHSQL : IAUTOHUBWITHSQL
{
        ClsDataAccess ObjData = new ClsDataAccess();

        public Responce Login(string sEmail, string sPassword)
        {
            Responce responce = new Responce();
            string sJson = "";

            try
            {
                sJson = ObjData.GetData("EXEC ProcLogin @email='" + sEmail + "',@Password='" + sPassword + "',@flag='L'");
                responce.Data = sJson;
                responce.Success = true;
                responce.Error = "";
            }
            catch (Exception ex)
            {
                sJson = ex.Message.ToString();
            }

            return responce;
        }

        public Responce AlterCustomerDocument(string data)
        {
            Responce responce = new Responce();
            string sJson = "";

            try
            {
                CustomerDocument cusdoc = JsonConvert.DeserializeObject<CustomerDocument>(data);
                string sProstring = "EXEC ProcCustomerDocument @id='" + cusdoc.id + "',@Userid='" + cusdoc.Userid + "',@VehiclelNo='" + cusdoc.VehiclelNo + "'";
                sProstring += ",@VehicleType='" + cusdoc.VehicleType + "',@DocumentType='" + cusdoc.DocumentType + "',DocumentName='" + cusdoc.DocumentName + "' ,@flag='L'";
                sJson = ObjData.AlterDB(sProstring);

                if (sJson.Equals("Sucess"))
                {
                    responce = GETCustomerDocument(Convert.ToInt32(cusdoc.Userid));
                }

                responce.Success = true;
                responce.Error = "";
            }
            catch (Exception ex)
            {
                sJson = ex.Message.ToString();
            }

            return responce;
        }

        public Responce GETCustomerDocument(int iUserid)
        {
            Responce responce = new Responce();
            string sJson = "";

            try
            {
                string sProstring = "EXEC ProcCustomerDocument @Userid='" + iUserid + "',@flag='S'";
                sJson = ObjData.GetData(sProstring);
                responce.Data = sJson;
                responce.Success = true;
                responce.Error = "";
            }
            catch (Exception ex)
            {
                sJson = " Faild";
                responce.Error = ex.Message.ToString() + sJson;
            }

            return responce;
        }
}

这是我的IAUTOHUBWITHSQL界面:

[ServiceContract]
public interface IAUTOHUBWITHSQL
{
    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "Login?sEmail={sEmail}&sPassword={sPassword}")]
    Responce Login(string sEmail, string sPassword);
    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "AlterCustomerDocument?data={data}")]
    Responce AlterCustomerDocument(string data);
    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GETCustomerDocument?Userid={iUserid}")]
    Responce GETCustomerDocument(int iUserid);
}

IAUTOHUBWITHSQL中,Login方法工作正常,但在运行post 2方法时,我收到了“Endpoint not found”错误。

这是我的web.config文件:

<configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
    <customErrors mode="Off" />
    <compilation debug="true" targetFramework="4.0" defaultLanguage="c++7">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
    </httpModules>
</system.web>
<system.serviceModel>
    <services>
        <service name="AutoHubWITHSQL.AUTOHUBWITHSQL" 
                 behaviorConfiguration="serviceBehavior">
            <endpoint 
                address="" 
                binding="webHttpBinding" behaviorConfiguration="jsonBehavior" 
                contract="AutoHubWITHSQL.IAUTOHUBWITHSQL" />
            <!--
            <endpoint 
                address=""
                binding="webHttpBinding" behaviorConfiguration="web"
                contract="AutoHub.IAutoHubService">
            </endpoint>
            -->
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="serviceBehavior">
                <serviceDebug includeExceptionDetailInFaults="true" />
                <serviceMetadata httpGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <!--
            <behavior name="web">
                <webHttp/>
            </behavior>
            -->
            <behavior name="jsonBehavior">
                <webHttp />
            </behavior>
            <behavior name="webBehavior">
                <webHttp helpEnabled="true" 
                         automaticFormatSelectionEnabled="false" />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <extensions>
        <behaviorExtensions>
            <add name="crossOriginResourceSharingBehavior" 
                 type="AutoHub.EnableCrossOriginResourceSharingBehavior, AutoHub, Version=1.0.0.0, Culture=neutral" />
        </behaviorExtensions>
    </extensions>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="ApplicationInsightsWebTracking" />
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
    </modules>
    <directoryBrowse enabled="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <httpProtocol>
      <customHeaders>
      </customHeaders>
    </httpProtocol>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

1 个答案:

答案 0 :(得分:1)

首先,你没有任何基地址,所以你需要添加一个。假设有一个地址。

 <host>
         <baseAddresses>
          <add baseAddress="http://localhost:8080/" />
         </baseAddresses>
        </host>

现在,您的服务托管在http://localhost:8080/

由于您的地址为“”,因此默认情况下只能访问一个端点,请为地址提供相对名称。

      <endpoint 
                address="HubSQL" 
                binding="webHttpBinding" behaviorConfiguration="jsonBehavior" 
                contract="AutoHubWITHSQL.IAUTOHUBWITHSQL" />
            <!--
            <endpoint 
                address="Hubservice"
                binding="webHttpBinding" behaviorConfiguration="web"
                contract="AutoHub.IAutoHubService">
            </endpoint>
可以通过http://localhost:8080/HubSQL/ IAutoHubService 合同访问

IAUTOHUBWITHSQL 相关合同  http://localhost:8080/Hubservice/

    <behavior name="web">
        <webHttp/>
    </behavior>