specify location in wsdl:import - wcf

I'm trying to have my WCF services run completely off HTTPS. However when WCF generates the WSDL it provides locations that are not secure (http) and not allowed (rejected) by server.
How do i get this:
<wsdl:import namespace="https://www.mydomain.com/ogc/csw/ebrim/wsdl1.1" location="http://www.mydomain.com/ogc/csw?wsdl=wsdl0"/>
to read this (notice location attribute now using https):
<wsdl:import namespace="https://www.mydomain.com/ogc/csw/ebrim/wsdl1.1" location="https://www.mydomain.com/ogc/csw?wsdl=wsdl0"/>
I can specify my namespace in my interface file but i don't' see how to specify location.:
[System.ServiceModel.ServiceContractAttribute(Namespace = "https://www.mydomain.com/ogc/csw/ebrim/wsdl1.1", ConfigurationName = "MyDomain")]
public interface ICatalog
{
I've tried modifying my baseAddress, but that didn't do anything.

You have to specify the httpsGetEnabled configuration property on the wcf stack. Check the following link to the MSDN

Related

Error on adding a service reference to use web-centric WCF service?

I am trying to follow a textbook learning how to create a web-sentric WCF service project. I created the service, and see the corresponding folder under Default Web Site on IIS. I can even browse the folder (localhost/EmployeeService/) and see the contents in the browser. Now I want to make a client, i.e. a simple Console application. When I am trying to add a Service Reference, after I enter the address, I get an error:
There was an error downloading 'http://localhost/EmployeeService/$metadata'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://localhost/EmployeeService/'.
The remote server returned an unexpected response: (405) Method Not Allowed.
The remote server returned an error: (405) Method Not Allowed.
Could you please explain? I saw some questions about the same error, but could not find a solution for myself.
Thanks.
In order to invoke the service, you must point at the service file. Otherwise the web server doesn't know what you're trying to do.
Add the .svc file to your URL to do that, so http://localhost/EmployeeService/YourService.svc.
You can also have it fileless, see How can I host a WCF service without an SVC file in IIS.

how to dynamic binding of web service URL

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.

Unable to change Culture in WCF

I'm running on a windows 2008 server. I have one Web service which calls a wcf service.
Within the WCF service it attempts to cast a date 20/08/2010 which fails because it thinks it in US format not Austrlaian.
So far I have:
On control panel change the region to English Australian under format
Under the Administrative tab I have also set system local to English (Austrlian)
within IIS7 at the default web site level I have changed Culture and UI culture under the .Net globalization.
I've also done this at the Web service and WCF Nodes
I have added the following to the Web service and WCF apps web.config file
<globalization requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-AU"
uiCulture="en-AU" />
This finally changed the culture in the Web service but the WCF service remains US culture.
Can anyone tell me what else I can try?
The WCF will ignore your globalization configuration if you do not set aspNet compatibility:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
...
To use that mode your service class must have the attribute AspNetCompatibilityRequirements set to Allowed or Required:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ServiceClass
{
...
}
This could work if you want to apply the Culture and CultureUI from config file.
Or you could either try to force the Culture in your WCF service code, if you are sure that it will not change dynamically. For instance, in your service class constructor. Note that this is not a best practice, perhaps you should use a Context initializer, but this one is quite simple.
public ServiceClass()
{
...
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-AU");
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-AU");
}
More info:
setting-cultureinfo-on-wcf-service-calls
using-call-context-initializers-for-culture
The problem is in the culture that is set for a user used in the application pool.
I found the following way to resolve this issue:
If the application pools uses ApplicationPoolIdentity change it to NETWORKSERVICE (unfortunatly I didn't found how to set regional settings for ApplicationPoolIdentity)
Set regional settings you need (en-AU) on the current user and than copy them for the system accounts as described here.
You can do it in the Global.asax.cs file, in the Application_Start file:
using System.Threading;
using System.Globalization;
public class Global : HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-AU");
}
}

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);

How to detect user agent in WCF web service

How can I detect the user agent in a web service? My web service is implemented using a WCF webservice with basicHTTPBinding. It will be a post from some SOAP clients. I wish to know the user-agent from the clients.
I shall like to see some sample code for this.
I am using a WCF based web service and in the svc.cs, I tried to catch this.Context.Request.UserAgent. But it gives the following error:
this.Context.Request.UserAgent 'MySoapService.MyService' does not contain a definition for 'Context' and no extension method 'Context' accepting a first argument of type 'MySoapService.MyService' could be found (are you missing a using directive or an assembly reference?)
I also tried System.Web.HttpContext.Current.Request.UserAgent and it says:
'System.Web.HttpContext.Current' is null
Edit note:
I tried to activate the ASP.NET compatibility mode. I added <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> in the config file and added [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] on the top of the class that implements the service interface. Then using System.Web.HttpContext.Current.Request.UserAgent gives me the user agent as desired.
There is another way to get the user agent without enabling ASP.NET compatibility in web.config:
string userAgent = WebOperationContext.Current.IncomingRequest.Headers["User-Agent"];
You can use also:
WebOperationContext.Current.IncomingRequest.UserAgent
You can read user agent from the HttpContext.Current.Request object if you enable ASP.NET compatibility in web.config:
What a totally unhelpful response!
This is not a trivial task. Yes it is obviously possible to get te user-agent string but how does one actually do it? I spent 2 hours checking google and so on but found the answer buried in MSDN documentation. In Visual Studio, from within a WebMethod try
this.Context.Request.UserAgent
That should do it!
User-Agent is a standard HTTP header. It'll be available to your web service just like it's available to anything CGI-like.
Did you even bother searching for this before posting your question? There must be millions of hits for it on Google.