Can't add ServiceReference - c#

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.

Related

WCF Change baseAddress

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.

c# - trying to build a web service client from WSDL but no config file is provided

I'm just getting familiar with WCF and I have to add additional functionality to a working web service at work. As I feel the need to be able to test the functionality before deploying it, I decided to build a test client. Here comes the problem.
I created a Console Application just for the purpose of a test client and tried to add a Service Reference through the provided WSDL but it didn't work. There was no config file created.. I tried first the "Add Service Reference" option in VS and when it didn't work, I tried creating the Proxy and Config files with svcutil.exe...
Just the proxy class gets created... When I try to instantiate a "client object" from that class, the following Exception is thrown: "Could not find default endpoint element that references contract 'eOrderingService.IeOrderingService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."
As this is a working service (a Czech company is using it), apparently there must be a way to create a web.config or app.config even manually but I have no idea where to start.. As I said I'm just getting familiar with WCF so I started looking online but most of the problems connected somehow to my issue were in different parts of the already created Config files.. I managed to bypass that exception adding the following to app.config:
<system.serviceModel>
<services>
<service name="eOrderingService" >
<endpoint
address="http://localhost:61472/eOrderingService.svc"
binding="webHttpBinding"
contract="eOrderingService.IeOrderingService" >
</endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint
address="http://localhost:61472/eOrderingService.svc"
binding="webHttpBinding"
bindingConfiguration=""
contract="eOrderingService.IeOrderingService"
behaviorConfiguration="web"
name="DeliveryNote" >
</endpoint>
</client>
The service has a lot of methods and the one I need to test is called 'DeliveryNote'.
So lets say the service is at this address:
http://localhost:61472/eOrderingService.svc
The POST method I need to call is:
http://localhost:61472/eOrderingService.svc/DeliveryNote
And respectively the GET method is:
http://localhost:61472/eOrderingService.svc/DeliveryNote?DocumentFilter={DOCUMENTFILTER}&CustomerID={CUSTOMERID}&FromDate={FROMDATE}
The links are working but I cannot figure out how to call them from the client.
When I tested calling the POST method I received another exception:
The remote server returned an unexpected response: (400) Bad Request.
That shouldn't be true because the request I'm sending is already tested and is a valid request in XML format.
So I tried to test with a different GET method that works and receives just two DateTime parameters and not a Xml. If I try the following link:
http://localhost:61472/eOrderingService.svc/PriceChanges?startDate=2018-08-29&endDate=2018-08-30
the result is OK..
But if I call the automatically generated method "PriceChanges" the result is NULL.
I just don't get what I do wrong. It seems like a connection to the service is established but the methods are not called/build correctly. Probably because I cannot comprehend how to build the <system.serviceModel> in app.config.
I definitely should read more about the web services but I don't know where to start.

No Endpoint listening

There was no endpoint listening at http://api/APIWCF.svc/soap that could accept the message. This is often caused by an incorrect address or SOAP action
I've created a new website in IIS called API, I assigned it to the folder of where my application is. But when I run it, it gives me error mentioned above.
What I've tried:
Deleted the website and re-added it in IIS.
I set my project to run under local IIS under web properties.
It's running under the current page.
I changed the virtual directory.
I checked the webconfig folder, which is as follows:
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
Have I done something wrong in IIS?
I cant figure it out.
change the Url in the client endpoint to have the host name
<endpoint address="http://[your host name]api/APIWCF.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_APIWCF"
contract="Bettingworld.JuiceAPIWCF"
name="BasicHttpBinding_APIWCF"/>
</client>

Cannot instantiate service client

I have a wpf C# application that calls a web service AddressValidationService. I know it used to work (before I started working on the project), but now it doesn't. The exception happens here:
var addrSvc = new AddressValidationServiceReference.AddressValidationServiceClient();
The exception is:
Could not find default endpoint element that references contract 'AddressValidationServiceReference.IAddressValidationService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
This is from my app.config:
<client>
<endpoint address="http://rdbval/EASTServices/AddressValidationService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPolicyRetriever"
contract="AddressValidationServiceReference.IPolicyRetriever"
name="BasicHttpBinding_IPolicyRetriever" />
<endpoint address="http://rdbval/EASTServices/AddressValidationService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAddressValidationService"
contract="AddressValidationServiceReference.IAddressValidationService"
name="BasicHttpBinding_IAddressValidationService" />
</client>
Maybe somebody could tell what is wrong? Thanks.
Probably stupid guess, but anyway: are you sure your config file is the one from your client application? =). try reading some AppSetting from it for example to ensure you are using the correct one if you are not sure.
The config itself looks fine.
You will need to Insert or Update the endpoints in your .config in the ServiceModel client project for IAddressValidationService

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