how to dynamic binding of web service URL - wcf

i store web service url in web.config or app.config. when i call web service like
ServiceAvailabilityTestClient.TestClient servAvailClient = new ServiceAvailabilityTestClient.TestClient();
servAvailClient.url= myapp.config url here.
servAvailClient.CallValidateCityPostalCodeZip();
the problem is the property called url is not appearing. sp please tell me what to do.
i just add wsdl file location as service reference because web service path called not being added. web service url which i try to add as web service reference is
https://devwebservices.purolator.com/EWS/V1/ServiceAvailability/ServiceAvailabilityService.asmx
1) i just not being able why i am not being able to add this web service url as service reference
2) why url property is not exposed in client side.
can anyone guide me what is the matter. thanks

You could do it through your generated client or ChannelFactory:
var client = ChannelFactory(IWcfService).CreateChannel(Binding, ServiceModel.EndpointAdress)
or
var client = New Client(binding, RemoteAdress)
EndpointAdress just takes string or uri in constructor e.g.http://yourservice.asmx

Are you using the <System.ServiceModel/> config section? If so you shouldn't have to do anything - the URL will be loaded from the <client/> section of the config when you create the channel.

Related

Blazor WASM Deploy to IIS Object reference not set to an instance of an object

I developed a Balzor WASM and it works on local machine with bellow structure :
But when I deploy to IIS it show me this error :
{"error":"Object reference not set to an instance of an object."}
It is very strange that has no any http 500 error in debug mode but when I hosted on IIS it shows me this error.
There is no any additional information in page or event viewer!
Another thing is I host both release and debug files on IIS. I shows me this message again!
Anyone can help me?
The error seems to be json and is strange that is on your index page of the WASM client.
The only possibility I can think is a request from your index.hrml to your backend but there's a problem of configuration.
Check your endpoint base address in your appsettings.json in your wwwroot of the client app.
Try to use postman (or another client like it) to test calls to your backend when hosted on IIS.

Web Api documentation with swashbuckle

We are currently trying to start writing WebApi services for our products switching from traditional WCF SOAP based services. The challenge we have got is how to provide the api documentation. I came across the SwaggerUi/swash buckle.
One limitation we have is we do not want to host the WebApi services in IIS but in a Windows Service. I am new to Web Api so I might be doing things the wrong way.
So for testing, I am hosting the web api in a console application. I can use the HttpClient to invoke the Get method on the Web Api but I can't access the same if I type the url in a web browser (is this normal for self hosted web api?).
So I installed the Swashbuckle.core nuget package and included the following code in the Startup class (Owin selfhosted).
var config = new HttpConfiguration();
config
.EnableSwagger(c =>
{
c.IncludeXmlComments(GetXmlCommentsPath());
c.SingleApiVersion("v1", "WebApi");
c.ResolveConflictingActions(x => x.First());
})
.EnableSwaggerUi();
private static string GetXmlCommentsPath()
{
var path = $#"{AppDomain.CurrentDomain.BaseDirectory}\WebApiHost.XML";
return path;
}
When I browse to the following location
http://localhost:5000/swagger/ui/index
I get "page cannot be displayed" in IE. Similar for chrome.
Is there anything special that needs to be done when hosting a WebApi in a console/windows service application to get the documentation automatically?
(I have enabled Xml documentation for the project)
I have now attached a test project. Please follow the link below:
Test project
Regards,
Nas
Your problem is not with Swashbuckle, which is configured correctly. Instead it is with the fact that your OWin web app has closed by the time the browser navigates to the swagger URI. Your using statement means that the web app is shut down at the end of it - well before Chrome has opened and navigated to the swagger path. You need to ensure the web app is still running - then your path will be valid (although in your source code you have different ports 9000 and 5000 in your url variables).

How to store configuration in Window8 RT Application?

I need to connect Win8 app to WCF service. The WCF client is created using Add Service Reference.
The requirement is to change the End point URL at runtime. Win 8 does not have app.config and instead use Application Data settings.
The problem is that App needs the URL at the startup. If URL is invalid, or cannot be reached, the app is terminated.
The question is, How to manage scenarios, where configuration settings are required for app startup, and to be set up at runtime?
When you create an instance of the client, before you start using it you can change the address for the service by accessing the Endpoint property of the client. Something like the code below.
var client = new ServiceReference1.ServiceClient();
client.Endpoint.Address = new EndpointAddress(yourNewUri);

WP7 dynamically change webservice url

I'm relying on a server backend for my WP7 app.
The server part is to be installed by the administrator on a host computer (not important).
I have to change the url in the app dynamically the first time the app is running on the phone (the user will be prompted to enter the url, and it will be saved in the isolated storage on the phone)
Question is: How do I change the url from the default app to point to the new url given by the user.
The webservice is a WCF service which holds all the data properties and collections, those I need in my app.
Let me know if
Actually I needed to change the url on the generated *Client.
So it looks like:
client.Endpoint.Address = new EndpointAddress(new Uri("http://server/service.svc);
If you're using c# you can change the service url by changing the url property on you serviceobject.
Service myService = new Service();
myService.Url = UrlToService;
myService.doLotsOfStuff();
Assuming its the same as full .NET, try this
WebSerivce.url = UrlFromUser.

How to instantiate a WCF DataServices Client without hard-coding the URI

I'm fairly new to WCF DataServices (OData) and I need to know the best way to instantiate the entity container on the client without hard-coding the URI. It seems like all of the examples on MSDN describe instantiating the client like this:
Uri uri = new Uri("http://www.someservice.svc");
DataServiceContext svc = new DataServiceContext(uri);
However, I know I must be missing something somewhere, because it doesn't make any sense to hard-code a service address like this. For one thing, how do you dynamically change the address when you move from Development to Test to QA to Production, when each environment is likely to have a different URI?
Thanks for any insights into this.
Put your DataService URL into e.g. your Settings file or just plain app.config:
Uri uri = new Uri(ConfigurationManager.AppSettings["ServiceURI"]);
DataServiceContext svc = new DataServiceContext(uri);
And in your app.config (or web.config for a web app):
<appSettings>
<add key="ServiceURI" value="http://www.someservice.svc" />
</appSettings>
Or grab it from a database config table..... or or or or or..... plenty of choices!
The URI is just a string - you can grab that from just about any configuration source you might have.
If you are working with a Silverlight app you can access the Uri of the xap with application.current.host
Then you can add a relative Uri to get the service Uri:
Uri base = application.current.host;
Uri relService = new Uri("..\someservice.svc", System.UriKind.Relative);
Uri service = new Uri(base, relService);
DataServiceContext svc = new DataServiceContext(service);