【问题标题】:WCF Web Service "POST [OperationContract]" returns "Endpoint not found", when published on IISWCF Web 服务“POST [OperationContract]”在 IIS 上发布时返回“找不到端点”
【发布时间】:2018-06-10 10:42:12
【问题描述】:

我创建了一个 WCF Web 服务。其中有一些带有 GET 请求的 [OperationContract] 和一个带有 POST 请求的 [OperationContract]。问题是,POST [OperationContract] 可以在 localhost 上正常工作,但在 IIS 上发布时会返回“找不到端点”错误。

这是我的 WCF 服务接口

接口 IService1.cs

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "UploadImage", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
    string UploadImage(Stream stream);

或(或者)

当我用这个 URL 调用这个 POST [OperationContract] 时:http://localhost:5031/Service1.svc/UploadImage,然后它工作正常。

但是

当我使用 URL: http://IP/Wcfservice1/Service1.svc/UploadImage 调用它时,它会返回 "Endpoint not found"


这是我的接口实现:

IService1.svc.cs

   public class Service : IService
    {
         public string UploadImage(Stream stream)
        {
            Random r = new Random();
            int index = r.Next(0, 99);

            System.Drawing.Bitmap imag = new System.Drawing.Bitmap(stream);
            byte[] imagedata = ImageToByte(imag);
            //Write code here to Save byte code to database..  

            stream.Read(imagedata, 0, imagedata.Length);
            FileStream f = new FileStream(@"E:\Studies\Uploaded Images\TestProfileImage" + index + ".jpg", FileMode.OpenOrCreate);
            f.Write(imagedata, 0, imagedata.Length);
            f.Close();
            stream.Close();
            return "Success";
        }
    }

 public static byte[] ImageToByte(System.Drawing.Image img)
        {

            ImageConverter converter = new ImageConverter();
            return (byte[])converter.ConvertTo(img, typeof(byte[]));

}

在我的 web.config 中,我有以下内容:

Web.config

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

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
        <bindings>
           <webHttpBinding>
        <binding name="WcfService1.WebHttp" maxBufferSize="2147483647"

                 maxBufferPoolSize="2147483647"

                 maxReceivedMessageSize="2147483647"

                 transferMode="Streamed"

                 sendTimeout="00:05:00">
          <readerQuotas  maxDepth="2147483647"

                         maxStringContentLength="2147483647"

                         maxArrayLength="2147483647"

                         maxBytesPerRead="2147483647"

                         maxNameTableCharCount="2147483647"/>
          <security mode="None" />
        </binding>
      </webHttpBinding>
        </bindings>

    <services>
      <service name="WcfService1.Service1">
        <endpoint address="" behaviorConfiguration="myweb" contract="WcfService1.IService1" binding="webHttpBinding" />
      <host>
       <baseAddresses>
           <add baseAddress="http://localhost:5031/Service1.svc" />
       </baseAddresses>
</host>
      </service>

    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name ="myweb">
          <webHttp/>
        </behavior>
      </endpointBehaviors>

      <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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpBinding" scheme="http" />
      <add binding="basicHttpsBinding" scheme="https" /> 
      <add binding="webHttpBinding" scheme="http"/>
    </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"/>
   <security>

                                <requestFiltering>

                                               <requestLimits maxAllowedContentLength="102400000" />

                                </requestFiltering>

                </security>
  </system.webServer>

</configuration>

请告诉我,这里有什么问题,我需要解决什么问题。 感谢您花时间查看这篇文章。 谢谢

【问题讨论】:

  • 我不认为这是 POST/GET 操作问题。这更像是一个路由问题。
  • 您是如何在 IIS 中配置应用程序的?有效的版本似乎是从 VS 运行的。 IIS 中根目录的应用路径是什么?
  • @RossBush 那我该怎么办?
  • @RossBush ,不,我没有在 IIS 中配置我的应用程序?你能指导我吗?
  • 你必须知道你的网络根权限,通常是IP。并从中分支并提出应用程序。你说你发布了,你能发布你发布到的url或位置吗?

标签: c# asp.net web-services wcf iis


【解决方案1】:

【讨论】:

  • 我认为该网站未正确托管。您是否已正确发布您的网站?
【解决方案2】:

能否请您从配置文件中删除主机部分,然后再试一次http://IP/Wcfservice1/Service1.svc/UploadImage? 更新:

尝试启用服务帮助页面。然后我们可以找出端点地址。将此部分添加到游览配置中:

    <endpointBehaviors>
        <behavior name="myweb">
            <webHttp helpEnabled="true" defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" />
        </behavior>
    </endpointBehaviors>

【讨论】:

  • 我删除了主机部分,然后再次尝试,但错误“找不到端点”仍然存在..?
  • 好的。你知道如何启用服务帮助页面吗?这很简单。我编辑了我的答案。启用帮助页面,看看你的端点地址是什么。
  • 我按照您的说明启用了帮助页面。这是我的服务的帮助页面... localhost:5031/Service1.svc 的操作此页面描述了此端点的服务操作。 Uri 方法描述 get 服务localhost:5031/Service1.svc/getUpdateUserDetail POST 服务localhost:5031/Service1.svc/UpdateUserDetailUploadImage POST 服务localhost:5031/Service1.svc/UploadImage
  • 我想它现在很清楚了亲爱的@Naveed。您的应用程序在 192.168.1.5 主机上不可用。您确定将应用程序配置为使用 iis 吗?您是否在 iis 中创建了新网站?
  • 是的@David,感谢您的帮助。你是对的,它在那里不可用。我再次添加并再次配置它。现在一切正常...谢谢
猜你喜欢
  • 1970-01-01
  • 2018-06-30
  • 1970-01-01
  • 2012-05-07
  • 2015-11-02
  • 2015-04-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多