在IIS上发布时,WCF Web服务“POST [OperationContract]”返回“未找到端点”

问题描述 投票:0回答:2

我创建了一个WCF Web服务。其中有一些带有GET请求的[OperationContract]和一个带有POST请求的[OperationContract]。问题是,POST [OperationContract]可以正常使用localhost但是在IIS上发布它会返回“Endpoint not found”错误。

这是我的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://192.168.1.5/Wcfservice1/Service1.svc/UploadImage,然后它返回“未找到端点”


这是我的接口实现:

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>

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

c# asp.net web-services wcf iis
2个回答

0
投票

请你从配置文件中删除主机部分并再次尝试这个http://192.168.1.5/Wcfservice1/Service1.svc/UploadImage?更新:

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

    <endpointBehaviors>
        <behavior name="myweb">
            <webHttp helpEnabled="true" defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" />
        </behavior>
    </endpointBehaviors>
© www.soinside.com 2019 - 2024. All rights reserved.