WCF service deployed to IIS7 server sitting on WinServer2008 Standard SP2.
DataContract int Members are being 'lost'
i.e. All ints sent by the client emerge as 0 into the Contract processing logic on the Server
I made a 'Reflection' contract (Take incoming int turn it to string and return it). When the test harness is pointed at the WCF Contract running in the IDE the ints are reflected OK. When it is pointed at the Deployed contract zeros are reflected.
Deployment:
Made an IIS Application on the Server and did a file deployment to the physical directory.
The Deployed Service appears OK. i.e. The 'real' client app (VS2008 WinMobile 6.5 app under development separate solution) has a WebService reference that sees the Deployed WCF OK . It is just that the variable values generated by the client get lost on the wire. Only happens to Client generated variables. The client is able to consume Server generated DataContract Variables with the expected values. It is something to do with base types. The first victim was client generated dates so I moved these into strings for the journey.
Web.config is below.
thanks
Bob
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Removed the web Application from Production server and remade it. Problem partially solved. Test windows app now sees the ints reflected. However the WinMobile client still doesn't. Tested using string values for the contract and it works. Life is too short for this. I shall alter the Contracts to strings strings strings. So much for strongly typed Data Contracts.
Related
To preface this, I have very little experience with servers and networking in general so I apologize if anything I say is incorrect or I am missing something simple.
I'm currently trying to create a WCF Service Application that I can make a HTTP request to from a different device on the same network and receive a response in the form of JSON. When I was using the Visual Studio Development Server to host the application I was able able to make these requests to my local host and get a response.
Request:
http://localhost:15021/Service1.svc/getData/myValue
Response:
{"GetDataResult":"You entered: myValue"}
Operation Contract:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getData/{value}")]
string GetData(string value);
Although this worked from my machine, if I tried a different one, changing localhost with the machines IP address, I would get no response. I started looking into this and it would seem that I need to host this with IIS if I want this functionality. I found quite a few tutorials on hosting WCF services with IIS, ex. http://www.codeproject.com/Articles/550796/A-Beginners-Tutorial-on-How-to-Host-a-WCF-Service.
The problem with these tutorials was they always used a console based 'client' to run the contracts whereas I need to do so with an HTTP request. Is there an easy way to do this?
Thanks in advance.
Edit:
I believe my web.config may be behind my issue, but not sure
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name ="MongoWCF.Service1" >
<endpoint address="../Service1.svc"
binding="webHttpBinding"
contract="MongoWCF.IService1"
behaviorConfiguration="webBehavior" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
You need to use system IP Address to consume WCF service.
You can share the link of your svc file which looks like http:// ip address here/Test/Service.svc
The client can use this to generate proxy and consume your service.
Below is the default layout for the web.config of a new WCF Service Application in VS2012.
What confuses me is that it doesn't seem to match any examples or tutorials online. There are no endpoints or bindings defined, yet it's possible to call the service.
I hit a problem when trying to increase the MaxReceivedMessageSize property - I googled it and didn't have a clue where to look in my web.config.
Can someone point me in the right direction of why it's so strangely laid out?
I expected it to look more like This SO question about setting MaxReceivedMessageSize or even any WCF tutorials like Michelle Bustamante's which is how I originally learned WCF.
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Starting with .NET 4.0, WCF introduced the concepts of default endpoints and bindings, allowing developers to create a service without having to define a bunch of stuff in the configuration file.
The posted config file is targeting 4.5, which is why you're seeing such a naked WCF config. If you need to increase your maxMessageSize, you'll need to explicitly define it in the config.
You can do this by either setting that binding definition as the default (by omitting the name attribute on the binding element), or creating an endpoint and explicitly assigning the binding configuration you defined via the bindingConfig attribute.
See A Developer's Introduction to Windows Communication Foundation 4.
You can also check a previous answer by me that has examples: https://stackoverflow.com/a/16099054/745969
I have been provided a code base where a WCF service is hosted in IIS. The project uses development server, but that does not matter.
The web.config file contains only the following section for service configuration:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
The .svc file contains the following:
<%# ServiceHost Language="C#" Debug="true" Service="TestApp.MySvcClass" CodeBehind="MySvcClass.svc.cs" %>
MySvcClass implements the contract (ISvcContract).
The thing is, under .NET 4, this configuration works. There is no declaration anywhere that establishes the link between the contract and the service types, there is nothing that links the behaviors to service type, there is no end point declaration, and yet it works.
With .net 3.5, it does not. It complains about the configuration.
What is the default behavior for WCF service projects' configuration?
Where is it documented?
Can I force these type of settings to fail?
I did not have the time to test, but if I add another svc file, the project would probably go crazy, since things may magically fall into place for a single service, but I'd rather not have configuration processed in a smart way.
A Developer's Introduction to Windows Communication Foundation 4
Read the Simplified Configuration section. It lists out default endpoints, protocols, bindings, etc.
I wanna learn WCF so I decided to try out creating some application that uses it. Well what I have in mind is I have 2 databases and I wanna create also an SSIS custom data source extension that calls the web service and passes the data (from one database) to an SSIS ADO.Net Data source (into the second database).
Now I created the 2 databases using SQL Server with one table in each. Then I Added a Connection in Visual Studio and then specified the server instance. (didn't create any .mdf files). I added this connectionString in the Web.Config file
<connectionStrings>
<add name="dbconnection" connectionString="
Data Source = SARE-VAIO;
Integrated Security = true;
Initial Catalog = Database1"/>
</connectionStrings>
When I wrote my service which basically populates Database1 with data, I wanted to define the endpoints but when I clicked on the "Edit WCF Configuration" it says 'No Service' is defined? What possibly am I doing wrong here? I want to create an error free service to be able to use it as a source in the SSIS package.
PS. My service has a basicHttpsBinding
UPDATE: I'm using VS 2012 with .Net Framework 4.5
UPDATE 2:
I skipped the endpoint definition for now and went ahead with testing and deploying my WCF. When I invoke the service it says the following error
Failed to invoke the service. Possible causes: The service is offline or inaccessible;
the client-side configuration does not match the proxy; the existing proxy is invalid.
Refer to the stack trace for more detail. You can try to recover by starting a new proxy,
restoring to default configuration, or refreshing the service.
Here is my web.config file
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="dbconnection" connectionString="Data Source = SARE-VAIO; Integrated Security = true; Initial Catalog = Database1"/>
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
To answer your questions
(1) Why WCF configuration editor shows 'No service is defined' error : Your web.config does not have any services and endpoints defined explicitly (Note: When you host this in IIS you will still get some endpoints added due to the defaults endpoint feature. But config editor tool shows only explicitly defined endpoints). That's the reason the config editor tool shows this message. But you can use the tool to add services and endpoints.
(2) After deploying the service see if the service successfully activated. You can do this by browsing to the metadata URL (your config has metadata enabled). Make sure your service WSDL help page and WSDL shows up fine. If not fix that issue first.
(3) If you are looking a default https endpoint after hosting it in IIS, make sure your IIS has https binding configured with an SSL certificate.
Hope this helps!
Thanks!
I'm creating a WCF service using Visual Web Developer Express 2010. I'd like to try out various bindings for educational purposes.
My memory from 2008 is that the web.config automatically included a section in for <services>, which I then would edit to change the endpoint binding, for example to basicHttpBinding
However my autogenerated 2010 service does not include <services> and any child endpoint or binding details under <system.serviceModel> (see web.config below). Do I need to add this element to the Web.config manually, or is there an alternative way that this should be configured? Or is this a limitation of the Express edition?
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false
and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
UPDATE 1 - I've found the following link which seems to describe the same behaviour - investigating now: http://forums.silverlight.net/t/166429.aspx/1
The version of Visual Studio doesn't matter here - it's the version of the .NET framework that is causing your confusion. In .NET 4.0 there are default WCF settings which means that a service can be hosted without any configuration.
MSDN Introduction to WCF 4 will explain more.
If you create the project as a .NET 3.5 project the configuration will be required (and will be added when you 'add new WCF service').
You can add the configuration in .NET 4.0, but if you are new to WCF it's easier if it were automatically generated so you had a starting point to work from.
It seems that WCF 4 creates a default end point if one isn't defined. From http://msdn.microsoft.com/en-us/library/ee354381.aspx
In an effort to make the overall WCF experience just as easy as ASMX,
WCF 4 comes with a new “default configuration” model that completely
removes the need for any WCF configuration. If you don’t provide any
WCF configuration for a particular service, the WCF 4 runtime
automatically configures your service with some standard endpoints and
default binding/behavior configurations. This makes it much easier to
get a WCF service up and running, especially for those who aren’t
familiar with the various WCF configuration options and are happy to
accept the defaults, at least to get started.