0
votes

I have created a WCF Web Service. Which have some [OperationContract] with GET request and one [OperationContract] with POST request. The problem is that, the POST [OperationContract] works fine with localhost but when published on IIS it returns "Endpoint not found" error.

Here is my WCF Service Interface

Interface IService1.cs

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

OR (Alternatively)

When I call this POST [OperationContract] with this URL: http://localhost:5031/Service1.svc/UploadImage , Then it works fine.

BUT

when I call it with URL: http://IP/Wcfservice1/Service1.svc/UploadImage , Then it returns "Endpoint not found"


Here is my Interface Implementation:

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[]));

}

and in my web.config I have the following:

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>

Please let me know, what's the problem here and what do i need to fix. Thanks you for taking time to have a look on this post. Thanks

2
I don't think this is POST/GET operation issue. It is more of a routing issue.Ross Bush
How have you configured your application in IIS? The version that works seems to be run from VS. What is the app path from your root in IIS?Ross Bush
@RossBush what should i do then ?Naveed
@RossBush , No i didn't configured my application in IIS? Can you please guide me on that?Naveed
You have to know your web root right, normally the IP. and from that you branch off and make applications. You say that you published,can you post the url or location that you published to?Ross Bush

2 Answers

0
votes

would you please remove the host section from your config file and try this http://IP/Wcfservice1/Service1.svc/UploadImage again? UPDATE:

try to enable the service help page. then we can find out the endpoint adress. add this section to tour config:

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