i have read multiple similar threads but still don't know what to do.
I've created simple WCF service which is getting some xml data (in strings)
Everything was working fine until project was running on windows 7.
Now, when i try to send data from client to WCF service i get exception
413-request-entity-too-large
i've tried to add these two parameters to my web.config on WCF service
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
Can someone please look at my config and try to help me ?
WCF service code:
public class Service1 : IService1
{
public static Konfiguracja config;
public static DBqueries queries;
public void WczytajKonfiguracje()
{
config = new Konfiguracja();
queries = new DBqueries();
}
public bool? DodajInfoSprzet(int idKlienta, string haslo, int id_zgloszenia, string HardwareInfoXML, string SoftInfoXML)
{
...and some code
}
}
and here is my wcf web.config file:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ProjektSerwisConnectionString" connectionString="Data Source=.\sql12;Initial Catalog=ProjektSerwis;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
</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>
(i've edited it by visual studio context menu on file web.config)
WCF service has been running by
namespace SelfService
{
class Program
{
static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost:55555/WcfStart/");
ServiceHost selfHost = new ServiceHost(typeof(Service1), baseAddress);
try {
selfHost.AddServiceEndpoint(typeof(IService1), new WSHttpBinding(), "WmiService");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
selfHost.Open();
while(true)
{
Console.WriteLine("Usługa działa");
Console.WriteLine("Wpisz quit aby zakończyć działanie");
string command = string.Empty;
command=Console.ReadLine();
if (String.Equals(command.ToLower(), "quit".ToLower()))
break;
}
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();
}
}
}
}
and client has just references to web service and connect it by :
Service1Client scl = new Service1Client();
bool? ok = false;
try
{
ok = scl.DodajInfoSprzet(IdKlienta, haslo, IdZgloszenia, HardwareInfoXML, SoftInfoXml);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
i konw that i have pasted a lot of code, but i have no idea what to do with my web.config file
the data which is being sending is not big, it is less than 1 MB
Did you just put this configuration in the web.config?
Since you're hosting your WCF as a console application you have to make the configuration in the App.config of the hosting application.
Related
I am creating a WCF service to store some data in a Xamarin.Forms application I am making. I have deployed this service to an Azure App Service. I am getting the following error when navigating to the URL:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /EventWCFService.svc
Code-behind of the WCF service:
public class EventWCFService : IEventWCFService
{
private static IEventService _eventService = new EventService(new EventRepository());
public void AddEvent(Event #event)
{
try
{
if (String.IsNullOrWhiteSpace(#event.EventTitle) || #event == null)
{
throw new FaultException("Event name is required");
}
_eventService.AddEvent(#event);
}
catch (Exception exception)
{
throw new FaultException($"Whoops... Something has gone wrong {exception.Message}");
}
}
public IList<Event> GetAllEvents()
{
return _eventService.GetAllEvents();
}
}
My WCF project also contains repositories and services:
IEventWCFService:
[ServiceContract]
public interface IEventWCFService
{
[OperationContract]
IList<Event> GetAllEvents();
[OperationContract]
void AddEvent(Event #event);
}
Web.Config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.8" />
<httpRuntime targetFramework="4.8"/>
</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>
Things I've tried:
First of all I tried to go to the properties and create a virtual directory - that did not work or solve the problem.
I tried to set the 'Specific page' to blank - it still did not solve the problem.
I tried to create a new app service - and I still got the problem.
I am quite new to WCF - so apologies if this may be a rookie mistake. I am a following a Pluralsight course and I was getting along quite well until the Azure deployment part.
I solved this problem by creating and deploying a new Azure App Service directly from the Azure portal rather than from Visual Studio itself. Then - I deployed the WCF service directly from the existing app service that I had just created.
I'm developing a WCF project using C# and I need to consume a web service with ws-security. Problem is I will only know the credentials to use at run time immediatly before consuming the web service, so I can't really use the webconfig file to setup the soap header security section.
My webconfig file looks like this:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="GuiaAcompanhamentoImplServiceSoapBinding1" maxReceivedMessageSize="1000000" useDefaultWebProxy="false">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://qualsiliamb.apambiente.pt/egar/services/GuiaAcompanhamentoWs/v2"
binding="basicHttpBinding" bindingConfiguration="GuiaAcompanhamentoImplServiceSoapBinding1"
contract="APAeGARv2.GuiaAcompanhamentoWs" name="GuiaAcompanhamentoWsPort1" >
<headers>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>XXXXXXXXXX</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXXXXXXX</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</headers>
</endpoint>
</client>
<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>
My C# code looks like this:
public string egAnularGuia2(string token, string nifInterveniente, string idUser, int idInstalacao, int idPda, string idMatricula, string numeroGuia, string codigoVerificacao, string Observacoes)
{
APAeGARv2.GuiaAcompanhamentoWsClient ws = new APAeGARv2.GuiaAcompanhamentoWsClient();
// I'd like to insert credencials for ws-security here, but don't know how
APAeGARv2.anularGuiaInput inp = new APAeGARv2.anularGuiaInput();
inp.tokenCertificacao = tokenCertificacao;
inp.nifInterveniente = nifInterveniente;
inp.idGuia = new APAeGARv2.identificadorGuia();
inp.idGuia.numeroGuia = numeroGuia;
inp.idGuia.codigoVerificacao = codigoVerificacao;
inp.observacoes = Observacoes;
APAeGARv2.anularGuiaOutput outp = new APAeGARv2.anularGuiaOutput();
try
{
outp = ws.anularGuia(inp);
}
catch (Exception Erro)
{
outp.result = ErroOutput2(outp.result, Erro);
}
return SerializeOutput(outp);
}
Using this method works very well. But as I've mentioned I'm limited to the credentials I set up in the webconfig file at design-time.
My question is: How can I change my C# code to be able to change credentials at run-time?
Thanks!
After a bit of research and asking a few coleagues someone came up with a solution which I tested and works well:
public string egAnularGuia2(string token, string nifInterveniente, string idUser, int idInstalacao, int idPda, string idMatricula, string numeroGuia, string codigoVerificacao, string Observacoes)
{
EndpointAddress address = new EndpointAddress("https://qualsiliamb.apambiente.pt/egar/services/GuiaAcompanhamentoWs/v2");
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
CustomBinding customBinding = new CustomBinding(binding);
SecurityBindingElement element = customBinding.Elements.Find<SecurityBindingElement>();
element.IncludeTimestamp = false;
APAeGARv2.GuiaAcompanhamentoWsClient ws = new APAeGARv2.GuiaAcompanhamentoWsClient(customBinding, address);
ws.ClientCredentials.UserName.UserName = "XXXXXXXXX";
ws.ClientCredentials.UserName.Password = "XXXXXXXXX";
APAeGARv2.GuiaAcompanhamentoWsClient ws = new APAeGARv2.GuiaAcompanhamentoWsClient();
// the rest remains the same...
}
I am new here. I want create a WCF WebService using Visual Studio and use it in Xamarin Forms application. This is my ultimate goal. Now I created WCF Service project and starts IIS service on my Mac machine(Windows 8 OS). But When I run the code already given in project to check whether things are alright or not, I am getting following error :
Failed to add a service. Service metadata may not be accessible. Make
sure your service is running and exposing metadata.
My Web.config file is as below :
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
</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>
Service.svc file :
<%# ServiceHost Language="C#" Debug="true" Service="Service" CodeBehind="~/App_Code/Service.cs" %>
Service.cs file :
public class Service : IService
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
I have been trying to get this working for hours now and have not had any luck. I am trying to create a WCF web service that has validation. I want the consumer of the service to be required to do:
ServiceReference1.XServiceClient client = new ServiceReference1.XServiceClient();
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";
before he can call any of the service methods. I found out that I have to create a CustomUserNamePasswordValidator so I created class library project in the solution to contain the Custom Validator class. I just wanted to verify that it works.
namespace XServices
{
public class CustomUserNameValidator : UserNamePasswordValidator
{
public override void Validate(string username, string password)
{
if (!(username == "test" && password == "password"))
{
throw new FaultException("Invalid username or password!");
}
}
}
}
Then I tried to make the necessary changes to my web.config file in the WCF project to support it. Unfortunately, this is where I had my first trouble.
Here is my web.config file as it is now.
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<!-- connection strings ommitted for security reasons -->
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</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>
<behavior name="CustomValidator">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="CustomUserNameValidator.XServices.CustomUserNameValidator, CustomUserNameValidator"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="Binding1">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
The MSDN docs are very unclear on how the customUserNamePasswordValidatorType works. The example https://msdn.microsoft.com/en-us/library/aa702565(v=vs.110).aspx completely glosses over it so I have no idea if I even did it correctly. And worse, it does not throw an error if what you put for that parameter is incorrect. It just silently ignores it. Long story short, the Validate method of my custom validator is not being called. I can't figure out why and I haven't found anything that has worked after hours of google searching. Please help.
In your service config, you forgot to associate the serviceBehavior with your service. Therefore your service don't know anything about your custom validator.
The following section is missing:
<services>
<service behaviorConfiguration="CustomValidator" name="ServiceName...">
<endpoint name="EndpointName..." bindingConfiguration="Binding1" address="..." binding="wsHttpBinding" contract="..." />
</service>
</services>
I've written a simple Java Console Application in Eclipse that references a WCF web service written in C#. Hosting the WCF service locally on my PC, I'm unable to connect to the service using the java client.
The steps I've taken to create the WCF Service are as follows
Create a 'Service1.svc' with the following endpoint:
string IService1.Hello(string sName)
{
return "Hello " + sName + "!" ;
}
The web config for the service is as follows:
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding"
contract="WcfService1.IService1" name="BasicHttpEndpoint" />
</client>
<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"/>
I modified the properties so the service will always use port 8888.
I've tested the service using a C# console application.
To Create the Java client, I did the following:
Download and install Glassfish 3.0.1 (Application server) which come bundled with Metro (Web Server)
Use the 'wsimport' tool in the 'bin'directory of my jdk to generate the service reference code for the java client app. The .bat file that I ran to create the service reference
Copy the code from step 2. above into a new Java Application in Eclipse.
Create a new Java class in my console app which calls the web service as follows
`
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import org.tempuri.Service1;
import org.tempuri.IService1;
public class Main {
/**
* #param args
*/
public static void main(String[] args) {
try {
Service1 service = new Service1(new URL("http://localhost:8888/Service1.svc?wsdl"), new QName("http://tempuri.org", "Service1"));
IService1 port = service.getBasicHttpBindingIService1();
((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8888/Service1.svc");
String sFileName = port.hello("Cal");
System.out.println(sFileName);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
e.printStackTrace();
}
}
}
`
The error I'm getting when I attempt to run my application is as follows:
Exception in thread "main" javax.xml.ws.WebServiceException: {http://tempuri.org}Service1 is not a valid service. Valid services are: {http://tempuri.org/}Service1
at com.sun.xml.ws.client.WSServiceDelegate.(WSServiceDelegate.java:237)
at com.sun.xml.ws.client.WSServiceDelegate.(WSServiceDelegate.java:182)
at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:106)
at javax.xml.ws.Service.(Unknown Source)
at org.tempuri.Service1.(Service1.java:42)
at Main.main(Main.java:17)
Any assistance with this is appreciated. Thanks.
change:
new QName("http://tempuri.org", "Service1")
to:
new QName("http://tempuri.org/", "Service1")
notice the extra "/" after org.