WCF Change baseAddress - c#

Fairly novice to WCF and doing a simple project in VS2017 using the WCF Service Library project template. Name the project MyBlahService and create it. Don't like the default file names Service1.cs and IService.cs so I rename them in the Solution Explorer. This causes some automatic renaming of the IService1 interface and Service1 class. Running from VS started WCF Service Host and WCF Test Client and everything seemed to work OK. Poking around in App.config, I see an entry using 'Service1' like below and change it to the second entry below.
Was:
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/MyBlahService/Service1/" />
</baseAddresses>
Now:
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/MyBlahService/MyBlahSvc/" />
</baseAddresses>
This change broke the service until I went back to Service1. I read all of the other posts that seemed relevant and noticed people had made similar changes, but they didn't explain how they did it. I did a 'grep' of all files in the project and failed to find any other occurrence of 'Service1' so it is a real mystery to me how to use anything other than 'Service1'. Any help?

This has nothing to do with baseAddress. When you rename IService1 and Service1, you also need to modify the service name and contract in the configuration file.
Here is my demo:
I changed IService1 to ITest and I need to change the contract in the configuration file:
Change Service1 to Test:
Feel free to let me know if the problem persists.
UPDATE
Baseadress can be set at will:
<add baseAddress="http://localhost:8733/Test" />
<add baseAddress="http://localhost:8733/Test/Test" />
......

I am accepting Ding Peng's answer because the effort put into it helped me solve the problem. There is something 'magic' about either the Design_Time_Addresses and/or specifying the port. You can put in other addresses easily if you leave both of those out.

Related

Adding ASMX service to IIS for use with Biztalk

I've created a local webservice (.asmx), that I want to add to IIS. The service needs to be called from a Send Adapter in Biztalk.
My project in Visual Studio is structured like so:
There's a single .asmx file, that contains a single web method, see code below:
public class LocalWebService : System.Web.Services.WebService
{
private BankConnectClient client;
[WebMethod]
public void TransferPayment()
{
ProcessDirectory("C:\\Test\\BankConnectTestFiles");
}
I'm not very familiar with IIS, so I don't know best approch to add this service to run on my localhost. I tried adding a new website and placed the project folder in C:\inetpub\wwwroot, which I then reference in IIS with the following settings:
But when I browse to the root http://localhost:61406/, I receive an HTTP Error 403.14.
What is the correct approach in deploying an asmx web service to IIS, to then call in Biztalk using either the WCF-Custom or WCF-BasicHttp adapter?
It seems that the problem has been solved. The service URL need the LocalWebService.asmx suffix.
Besides, as far as I know, BasicHttpBinding in the WCF aims to compatible with ASMX web service, why not try to create a WCF service with BasicHttpBinding. And this is also supported by the BizTalk.
I Have made a demo, wish it is useful to you.
VS template.
Add the following code snippets to the default webconfig.
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
<!--add the following line to support http protocol-->
<add binding="basicHttpBinding" scheme="http"/>
</protocolMapping>
Then publish the project to the IIS folder and add the http binding to the IIS site binding module. We might need to enable the WCF support.
Result.
Feel free to let me know if there is anything I can help with.

ASMX Webservice - The test form is only available for requests from the local machine

I have an ASMX webservice with two functions. One sends a JSON object to the server and stores it in a file, while the other function retrives the JSON object from the server. The webservice works perfectly in local, but when I try it in a remote server, I get the well known "The test form is only available for requests from the local machine" error.
As suggested in different forums, I have added the protocols to my web.config file:
</system.web>
<webServices>
<protocols>
<add name="HttpSoap12"/>
<add name="HttpSoap"/>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
Adding the POST protocol makes the second function (the one that retrives the object) available from remote, but the first one is still only available from the local machine.
I haven't been hable to find the solution to this problem, as every solution I found was just to add the protocols in the web.config file, which only work for one of the two functions.
There is one question which seems to have a similar problem, caused by using DateTime type as input parameter. In my case, maybe it has something to do with using a "Object" type as imput for the function? What alternatives do I have if I can't use the Object type?
Any suggestion will be helpful.
Thank you and best regards,
I had this same issue. VS 2012 did not publish the web.config to my published source after I added ws protocols. It worked when I manually copied the file.
Another reason this can happen is that your parameters are more complex objects, including things like GUIDs

System.Runtime.Remoting.RemotingException: Requested Service not found

I have the following code in my Web.Config in a remoting project which is having a reference to a dll of another class library. The class library has the following class inside it:
public class Generator: MarshalByRefObject, IGenerator
{
}
When I run the remoting project for the configured uri which is exposing the above class, I get the mentioned error in the question header.
The url I run is this:
http://localhost/documentgenerationserver/Generator.rem
<application>
<service>
<wellknown mode="SingleCall" objectUri="Generator.rem" type="ABC.Generator, Generator" />
</service>
<channels>
<channel ref="http" />
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channels>
</application>
Can someone advise me, how to resolve this issue?
EDIT 1: After going through an article on remoting on google, I tried appending ?wsdl to my URL above and it worked. It shows me WSDL file for my remote object. In my Client Project which is an asp.net web application hosted in IIS 7.5, when I instantiate the remote object using following:
Activator.GetObject()
It successfully instantiates, but when I use this proxy of remote to call its method, it does not reach up to that method and returns immediately.
Can some one please help me knowing, how can I at least debug it and see, what's happening. Why it is not reaching to the remote object method?
The message "System.Runtime.Remoting.RemotingException: Requested Service not found" is the expected behavior on the browser for a remoting service.

Can't add ServiceReference

Metadata contains a reference that cannot be resolved
As I understand, WSDL address is on remote server, but it has links to XSD's inside as "localhost", and my VisualStudio can't resolve it. If I download wsdl and change "localhost" to remote address - it works fine, but xsds has another links inside with localhost.
And I don't think that downloading whole service is the right way :)
What can I do?
Added: And SoapUI can't load this service ether: "Error loading [http://localhost:7733/ESchoolService?wsdl=wsdl0]: java.io.IOException: Attempted read from closed stream"
This is quite simple to be fixed, just changing the baseaddress url in the configuration file for the service. I understand that you don't have access to the source code, but do you have access to the configuration file? If you do, just find the baseAddress element, and replace the localhost by the server name (or a known DNS). Here is an example:
<host>
<baseAddresses>
<add baseAddress="http://MyServerName:7733/ESchoolService" />
</baseAddresses>
</host>
I hope it helps.
Cheers,
Rob.

Confused by use of host name in WSDL file in C# Web Service

I have created a WCF web service in C# deployed in a Windows Service EXE which is largely working the way I want. I am using it in a self-hosted manner (not within IIS).
In order to make a WSDL file available to the calling Java webservice, I added ServiceMetadataBehavior to the host creation. i.e:
ServiceHost host = new ServiceHost(typeof(MyService));
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
host.Open();
This all worked fine until I moved my service to another server with a different host name. When I connect to the WSDL (http://prod-server:55000/MyService?wsdl), I see that the host name of the development server is hard coded in the WSDL.
Here is a snippet of the WSDL as seen in a browser:
<wsdl:definitions name="MyService" targetNamespace="http://tempuri.org/">
<wsdl:import namespace="MyProject.ServiceContracts" location="http://dev-server:55000/MyService?wsdl=wsdl0"/>
<wsdl:types/>
I have checked all of the C# code in the project, and the development server name is not hard coded anywhere.
In the App.config file, I have the following defined:
<system.serviceModel>
<services>
<service name="MyService">
<endpoint address="http://localhost:55000/MyService" binding="basicHttpBinding"
bindingConfiguration="" contract="MyProject.ServiceContracts.IMyInterface" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:55000/MyService" />
</baseAddresses>
</host>
</service>
</services>
I would expect that this would result in the localhost machine name being substituted, but it persists as the development box name on which the service was originally created / deployed. Am I mistaken?
I also looked into the possibility of explicitly specifying a path to my WSDL file, but from what I can deduce, this can only be done if hosting the service on IIS.
Lastly and purely out of curiosity, I wonder if an actual WSDL file actually gets created (a physical file on disk I mean) or is it dynamically rendered with each request?
It is created dynamically, not every call IIRC, but on first request to the metadata endpoint. I'm not sure why your seeing your DEV server name on the non-DEV machine, but, because you're specifying localhost only in your endpoint address it's going to resolve DNS using the primary network address for the server. You may want to consider adding the useRequestHeadersForMetadataAddress behavior to your config so that the DNS with which the service is accessed is actually used instead.
With WCF the WSDL is dynamically generated.
I have had this problem a number of times on a WCF 3/3.5 service when I needed to send a WSDL to someone as a file. Typically what I do is save the files (typically there are 3, a wsdl for the service, an xsd for your types, and an xsd for the .net types, but your mileage may vary), then manually update the wsdl imports to reference the other two files relative to the wsdl file, then send all three files.
The wsdl:service , wsdl:port, and soap:address will still reference the dev server, but most ws client libraries account for this and allow the developer to configure the endpoint.

Categories