2

I made a small console application that hosts a WCF Service, this application is also the client and implements the Service.

It works fine on my local machine and returns the data in JSON to the webbrowser. Im using the Chrome browser with Advanced Rest CLient, but also used a javascript client and succesfully read the response.

I deployed the executable on the server and changed the endpoint adres to the domainname. Visiting the service on the domain on the right port also shows the Service is activated, i can also acces the wsdl remotely.

When i try to Post i get a http 400 bad request error. I have not been able to figure out why this works fine locally but not on a remote server.

[ServiceContract]
    public interface IService
    {
        [WebInvoke(UriTemplate = "/getRecipes/",
            Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
        [OperationContract]
        object[][] getRecipes();
    }

public class Service : IService
{
    private static bool IgnoreCertificateErrorHandler(object Sender,
                                            System.Security.Cryptography.X509Certificates.X509Certificate Cert,
                                            System.Security.Cryptography.X509Certificates.X509Chain Ch,
                                            System.Net.Security.SslPolicyErrors PolErr)
    {
        return true;
    }

    public object[][] getRecipes()
    {

        //this is the place where implement a client implementation of a webservice and it full the object array beneath, this returns more then 200 rows.
        object[][] QueryResult; 
        return QueryResult;
    }
}

App.config:

<system.serviceModel>
    <services>
      <service name="CS.Service" behaviorConfiguration="PageBehave">
        <host>
          <baseAddresses>
            <add baseAddress="http://domain.com:9001/Service"/>
          </baseAddresses>
        </host>
        <endpoint address="http://domain.com:9001/Service" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="CS.IService"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="PageBehave">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

UPDATED:

This application is a bridge to communicate with a remote webservice. Currently the error im getting is: The remote name could not be resolved:

. The exception stack trace is:
System.Net.HttpWebRequest.GetRequestStream(TransportContext&amp; context)
       at System.Net.HttpWebRequest.GetRequestStream()
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   `at ConsoleApplication1.ABC.ABC.select(String sql, Object[] params) in` 

c:\Users\---\Desktop\--\--\Web References\ABC\Reference.cs:line 81
       at CS.Service.getRecipeDetails(String number) in c:\Users\--\Desktop\---\ConsoleApplication1\Program.cs:line 134
       at SyncInvokegetRecipeDetails(Object , Object[] , Object[] )
       at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs)
       at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)


 at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

This bridge application works perfect on any local machine i tried. Just the server is giving problems.

Vern
  • 147
  • 2
  • 14
  • Is there any reason why you are using Method = "POST" when you don't have any arguments passed to getRecipes()? Using GET method might help. – Dinesh Mar 12 '15 at 03:27
  • I changed it to a GET, but it does not have an effect. It works locally but on the remote server it does not work. I also made a new method that returns a static object array containing strings. It seems this can be request succesfully as the response showed up in the XMLHttpRequest. Could my first method have a to large response size? Eventhough this works fine locally does this matter on a remote server? – Vern Mar 12 '15 at 11:14

2 Answers2

1

Try removing the value for address attribute...

<endpoint address="" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="CS.IService"/>
Dinesh
  • 470
  • 4
  • 13
  • I changed it but it has no effect. I do know what is causing the problem but i dont know how to fix it yet. When the service is called it returns the following message: The exception message is 'The remote name could not be resolved From within my WCF method i make a request to another service located that a https domain. However this works well on any computer i put the executable on. Just the server has problems finding the remote server from within the method. – Vern Mar 16 '15 at 12:00
1

Solved this issue. The host file on the server had to include the remote server i was trying to acces from the wcf service.

Vern
  • 147
  • 2
  • 14