0

I am setting up an ASP.Net WebForms sub-domain with WCF hosted on a shared hosting account. WCF is the primary purpose of the site at the moment. I am having trouble establishing a link from my desktop yielding a perpetual

Unable to connect to the remote server

I am trying from both Add Service Reference and from C#. I want C# code at the end on the client.

I keep playing around with port numbers and different types of bindings, but nothing works.

Web.config:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.6.2"/>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
    <system.serviceModel>
        <services>
            <service name="MyCloud.Communication.CloudService" behaviorConfiguration="BehaviorMyCloudService">
                <endpoint address=""
                                    binding="wsHttpBinding"
                                    bindingConfiguration="EndpointBindingMyCloudService"
                                    contract="MyCloud.Communication.ICloudService"
                                    behaviorConfiguration="web"
                                    >
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost/MyCloudService/"/>
                    </baseAddresses>
                </host>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="BehaviorMyCloudService">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                    <dataContractSerializer maxItemsInObjectGraph="2147483647" />
                    <useRequestHeadersForMetadataAddress>
                        <defaultPorts>
                            <add scheme="http" port="8080" />
                        </defaultPorts>
                    </useRequestHeadersForMetadataAddress>
                </behavior>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="web">
                    <webHttp />
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <bindings>
            <wsHttpBinding>
                <binding
                    name="EndpointBindingMyCloudService"
                    allowCookies="false"
                    closeTimeout="00:01:00"
                    openTimeout="00:01:00"
                    receiveTimeout="00:10:00"
                    sendTimeout="00:01:00"
                    maxBufferPoolSize="524288"
                    maxReceivedMessageSize="2147483647"
                    messageEncoding="Text"
                    textEncoding="utf-8"
                    transactionFlow="false"
                    useDefaultWebProxy="true"
                    >
                    <security mode="None">
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
            <baseAddressPrefixFilters>
                <add prefix="http://localhost:8080"/>
            </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
    </system.serviceModel>
</configuration>

CloudService.svc (C# Code):

using System;
using System.IO;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.Web;

namespace MyCloud.Communication
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class CloudService : ICloudService, IErrorHandler
    {
        public UInt16 GetServiceId()
        {
            return MyCloudLibrary.Constants.My_Id_CloudService;
        }
    }
}

ICloudService.cs:

using System;
using System.IO;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace MyCloud.Communication
{
    [ServiceContract(SessionMode = SessionMode.Allowed/*, CallbackContract = typeof(ICallbackCloudService)*/)]
    public interface ICloudService
    {
        [OperationContract(IsOneWay = false)]
        [FaultContractAttribute(typeof(CloudServiceFault))]
        UInt16 GetServiceId();
    }
}

Client Side C# Code:

WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.None;
EndpointAddress endpointAddress = new EndpointAddress("http://Mycloud.asdfmydomain.com/MyCloudService");
var pipeFactory = new ChannelFactory<ICloudService>(binding, endpointAddress);
Program.HostIpcCloudService = pipeFactory.CreateChannel();
Program.HostIpcCloudService.Connect();
CommCloudService.IsPipeCloudService = true;
UInt16 serviceId = Program.HostIpcCloudService.GetServiceId();

Client Side C# Error:

OuterException:

"There was no endpoint listening at http://mycloud.asdfmydomain.com/MyCloudService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."

InnerException:

"The remote server returned an error: (404) Not Found."

The Add Service Reference from Visual Studio 2017 said the same thing.

I got similar code working from my Windows Service, so maybe the problem is that I am going cross machine, possibly ports, possibly a firewall on the hosting account, etc.

Some (but not all) references:

Thoughts?

UPDATE BASED ON ANSWER 1:

(SO should pay me a pain and suffering fee for having to endure this hugely annoying celebration April Fool's theme. I am attempting to focus on programming and stay focused.)

I am making progress, no dice yet.

My no service found error message and duplicated MyCloud.Communication.MyCloud rather than MyCLoud.Communication.CloudService error message was the result of an incomplete refactoring on the part of Visual Studio. Visual Studio did NOT refactor the .SVC markup file.

<%@ ServiceHost Language="C#" Debug="true" Service="MyCloud.Communication.CloudService" CodeBehind="CloudService.svc.cs" %>

Specifying in a browser the following URL yields:

http://mycloud.asdfmydomain.com/Communication/CloudService.svc/Address1

Here is a key part of the URL from the Microsoft link:

or you can provide a base address for the ServiceHost of a service and then specify an address for each endpoint associated with this service that is defined relative to this base address. Path: /mathservice.svc/secureEndpoint

I had to remove the commented out <serviceHostingEnvironment because the browser wanted multipleSiteBindingsEnabled="true".

The text says that the first part of the URI is the path to the SVC file followed by the endpoint address name specified in the EndPointAddres tag.

Error Via Chrome:

[ServiceActivationException: The service '/Communication/CloudService.svc' cannot be activated due to an exception during compilation.  The exception message is: The endpoint at 'http://mycloud.asdfmydomain.com/Communication/CloudService.svc/Address1' does not have a Binding with the None MessageVersion.  'System.ServiceModel.Description.WebHttpBehavior' is only intended for use with WebHttpBinding or similar bindings..]

Error Via C#:

{"The requested service, 'http://mycloud.asdfmydomain.com/Communication/CloudService.svc/Address1' could not be activated. See the server's diagnostic trace logs for more information."}

I am making progress.

Sarah Weinberger
  • 15,041
  • 25
  • 83
  • 130

1 Answers1

0

In you web.config you write

 <baseAddresses>
                    <add baseAddress="http://localhost/MyCloudService/"/>
                </baseAddresses>

When you call the service , the address is http://Mycloud.asdfmydomain.com/MyCloudService ,which mismatches the address configuration in your web.config.

If you are not sure what address your service is, you could see it through wsdl.

For example , my web.config is

<service name="Service.CalculatorService" >
    <endpoint address="Calculator.svc/abc/" binding="basicHttpBinding"  contract="ServiceInterface.ICalculatorService" ></endpoint>
   <host>
      <baseAddresses>
        <add baseAddress="http://localhost:62193/"/>
      </baseAddresses>
    </host>
  </service>

Then when I input address of my service's wsdl address http://localhost:62193/Calculator.svc?singleWsdl.

I could find address of my service through the wsdl at the bottom. enter image description here

You could see even I only write one Calculator.svc , there are still two Calculator.svc.

Because baseaddress will be combined with your svc first and then combined with relative address. So the final address will be baseaddree + svc + relativeaddress.

Please refer to the link below WCF: relativeAddress,baseAddress and binding

Ackelry Xu
  • 756
  • 3
  • 6