I am trying to use the following class in a Windows Communication Foundation project written in Visual Studio 2012:
[DataContract]
public class SimCoilData : SimInventoryItemData
{
[DataMember]
public UnitTemperature? RequiredCoolingHotspot { get; set; }
[DataMember]
public UnitTemperature? RequiredHeatingColdspot { get; set; }
[DataMember]
public UnitTemperature? HeatingHotspotLimit { get; set; }
[DataMember]
public TimeSpan? TimeToRequiredColdspot { get; set; }
[DataMember]
public TimeSpan? TimeToRequiredCoolingHotspot { get; set; }
[DataMember]
public TimeSpan? TimeToHeatingHotspotLimit { get; set; }
[DataMember]
public UnitLength Gauge { get; set; }
[DataMember]
public UnitLength Width { get; set; }
[DataMember]
public double[] Temperatures { get; set; }
public SimCoilData() : base()
{
}
}
Before the addition of the Temperatures array, data was being exchanged well between the server and the client. I added the Temperatures array, rebuilt the server application, and ran it. Then, in the client project, I updated the service reference and rebuilt the project. When I run the client, I get an error message that a meaningless reply was received, which could be caused by a few things, including a data contract mismatch. I have verified that the array is being populated on the server side. What is the correct procedure for adjusting my client application to accept the array?
The problem appeared to be that I had not reserved enough space in the client for the messages. I found that I could handle 250 doubles per object but not 300 doubles per object. A Google search for "WCF maximum message size" led me to the maxBufferSize and maxReceivedMessageSize parameters. With this configuration for my client, I was able to get all 1800 values in my arrays:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_ISimShopServiceLib"
openTimeout="00:01:00"
closeTimeout="00:00:05"
sendTimeout="00:01:00"
receiveTimeout="00:01:00"
maxBufferSize="5000000"
maxReceivedMessageSize="5000000">
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:1236/SimShopService" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_ISimShopServiceLib" contract="SimShopServiceReference.ISimShopServiceLib"
name="NetTcpBinding_ISimShopServiceLib">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Related
I'm trying to bind a property via MVVM pattern.
The payload is something like that:
{
"QualificationSummary": "For all positions individuals must have IT-related experience...",
"PositionRemuneration": [
{
"MinimumRange": "62639.0",
"MaximumRange": "137348.0",
"RateIntervalCode": "PA"
}
]
}
I Tried this, but did nor worked.
<Label>
<Label.Text>
<MultiBinding StringFormat="{}{0}{1}">
<Binding Path="PositionRemuneration[MinimumRange]"/>
<Binding Path="PositionRemuneration[MaximumRange]"/>
</MultiBinding>
</Label.Text>
</Label>
Any clues?
After spend some time understanding the problem, that's the solution.
The c# class:
public Positionlocation[] PositionLocation { get; set; }
public class Positionlocation
{
public string LocationName { get; set; }
public string CountryCode { get; set; }
public string CountrySubDivisionCode { get; set; }
public string CityName { get; set; }
public float Longitude { get; set; }
public float Latitude { get; set; }
}
and to access the property:
<Binding Path="MatchedObjectDescriptor.PositionLocation[0].LocationName"/>
Using: Entity Framework, Sql Server 2014.
My application locale/globalisation is not set (yet).
My problem is this;
When dealing with dates all around the application they are in the correct UK date format:- dd/mm/yyyy
However, when I use those dates and enter them in to my SQL database (on a shared hosted SQL Server), they go in in the US format mm/dd/yyyy.
How can I change it so that the dates go in to the database in the UK format? Bear in mind I can't touch the settings on the server.
I'm thinking through the connection string with a locale setting or in web.config, but I can't find anything definitive online that can tell me for sure.
I was thinking that this would sort it out but haven't tried it yet.
<configuration>
<system.web>
<globalization
fileEncoding="utf-8"
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-GB"
uiCulture="en-GB"
/>
</system.web>
</configuration>
EDIT: This is the code generated by EF
public int CreatedBy { get; set; }
public System.DateTime CreatedDate { get; set; }
public Nullable<int> ModifiedBy { get; set; }
public Nullable<System.DateTime> ModifiedDate { get; set; }
public bool Enabled { get; set; }
public Nullable<int> ProductSettingId { get; set; }
public Nullable<int> ProductAreaMinimumPremiumId { get; set; }
public int ProductId { get; set; }
public int StatusId { get; set; }
public Nullable<System.DateTime> InceptionDate { get; set; }
public Nullable<decimal> Gross { get; set; }
public Nullable<decimal> Ipt { get; set; }
I'm having issues with all the DateTime properties.
If the date in the UI/app is 12/01/2017 it will go in the DB as 1st Dec 2017 whereas it should be 12th Jan 2017.
I'm must apologise everyone! It turns out my issue was with the application culture/locale.
By adding:
<configuration>
<system.web>
<globalization
culture="en-GB"
uiCulture="en-GB"
/>
</system.web>
</configuration>
That worked.
I did run this line in on my DB as well, first so I don't know if both these together sorted it out.
ALTER LOGIN {{MY LOGIN}} WITH DEFAULT_LANGUAGE=British
I have this bug when i try to create a new user using a remote wcf service, other services work fine.
{"The HTTP request was forbidden with client authentication scheme 'Basic'."}.
My user controller
[AcceptVerbs("Post")]
public ActionResult Add(FormCollection collection)
{
_userRepository.Add(collection["Company"], collection["Email"], collection["ExternalIdentifier"]);
return RedirectToAction("LoggedInAsAdministrator", "Home");
}
my user repository
public void Add(string company, string email, string eid)
{
var user = new User { Company = company, Email = email, ExternalIdentifier = eid, AccountType = "pro", CountryCode = "NL", Language="EN" };
var createdUser = _proxy.CreateUser(user);
((IDisposable)_proxy).Dispose();
}
my user.cs:
[ServiceContract]
[XmlRoot("user")]
public class User
{
[XmlElement("company")]
public string Company { get; set; }
[XmlElement("country-code")]
public string CountryCode { get; set; }
[XmlElement("language")]
public string Language { get; set; }
[XmlElement("created-at")]
public DateTime? CreatedAt { get; set; }
[XmlElement("email")]
public string Email { get; set; }
[XmlElement("external-identifier")]
public string ExternalIdentifier { get; set; }
[XmlElement("id")]
public int? Id { get; set; }
[XmlElement("measurement-system")]
public string MeasurmentSystem { get; set; }
[XmlElement("profile")]
public string Profile { get; set; }
[XmlElement("url")]
public string Url { get; set; }
[XmlElement("username")]
public string Username { get; set; }
[XmlElement("account-type")]
public string AccountType { get; set; }
[XmlElement("current-token")]
public string CurrentToken { get; set; }
}
my servermodel configuration
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="UsernameWithTransport">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint address="xxxxxxx" binding="webHttpBinding" bindingConfiguration="UsernameWithTransport" behaviorConfiguration="xxxxx" contract="xxxxx" name="xxxxx" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="xxxxxxxx">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Any Help PLEASE.
Since you have enabled basic authentication on service you need to send basic credentials (username/password) with request. Try adding following code before you call your service.
_proxy.ClientCredentials.UserName.UserName = "myuser";
_proxy.ClientCredentials.UserName.Password = "mypassword";
I'm developing a sample system that use Entity Framework code first approach and MVC as user interface. Here I use WCF services to communicate with user interface and the system. When I use a List or a collection in my Employee entity It given following error. I'm sure that's due to the collection.
" An error occurred while receiving the HTTP response to http:/localhost/GreetingHost/EmployeeService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details. "
Here are my entities and services that included in Greeting Project :
Employee.cs
[DataContract]
[KnownType(typeof(Greeting))]
public class Employee
{
[Key()]
[DataMember]
public string UserId { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public int Age { get; set; }
[DataMember]
[ForeignKey("EmployeeUserID")]
public virtual IList<Greeting> Greetings
{
get
{
if (this._greetings == null)
{
this._greetings = new List<Greeting>();
}
return _greetings;
}
set { _greetings = value; }
}
private IList<Greeting> _greetings;
}
Greeting.cs
[DataContract]
public class Greeting
{
[Key()]
[DataMember]
public int GreetingID { get; set; }
[DataMember]
public string Salutation { get; set; }
[DataMember]
public string Message { get; set; }
[DataMember]
public DayStatusWrapper DayStatusWrapper { get; set; }
[DataMember]
public string EmployeeUserID { get; set; }
[DataMember]
public virtual Employee Employee { get; set; }
}
GreetingDBContext.cs
public class GreetingDBContext :DbContext
{
public DbSet<Greeting> Greetings { get; set; }
public DbSet<Employee> Employees { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Employee>().
HasMany(d => d.Greetings).
WithRequired(c => c.Employee).
HasForeignKey(c => c.EmployeeUserID).WillCascadeOnDelete();
modelBuilder.Entity<Employee>()
.HasKey(c => c.UserId);
modelBuilder.Entity<Greeting>()
.HasKey(c => c.GreetingID);
}
}
EmployeeServices.cs
public class EmployeeService
{
private GreetingDBContext db = new GreetingDBContext();
public void AddEmployee(string UserId, string Name, int Age)
{
Employee emp = new Employee();
emp.UserId = UserId;
emp.Name = Name;
emp.Age = Age;
db.Employees.Add(emp);
db.SaveChanges();
}
public Employee getEmployee(string UserId)
{
Employee selectedEmployee = null;
foreach (Employee item in db.Employees)
{
if (item.UserId == UserId)
{
selectedEmployee = item;
break;
}
}
return selectedEmployee;
}
}
I used WCF Service application to host the services. Here codes are from GreetingHost project.IEmployeeServices.cs
[ServiceContract]
public interface IEmployeeService
{
[OperationContract]
void AddEmployee(string UserId, string Name, int Age);
[OperationContract]
Employee getEmployee(string UserId);
}
EmployeeService.svc.cs
public class EmployeeService : IEmployeeService
{
Greeting.EmployeeService serviceImplementation = new Greeting.EmployeeService();
public void AddEmployee(string UserId, string Name, int Age)
{
serviceImplementation.AddEmployee(UserId,Name,Age);
}
public WcfGreating.Employee getEmployee(string UserId)
{
return serviceImplementation.getEmployee(UserId);
}
}
Service host successfully :
In my MVC application Used above service reference:
EmployeeServiceClient employeeService = new EmployeeServiceClient();
public ActionResult Profile(string id)
{
Employee emp = employeeService.getEmployee(id);
return View(emp);
}
When gathering employee from service , above mentioned CommunicationException was returned. Can anyone help me?
Thank You!
Edit :
Clients' Web.config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="EmployeeService" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/GreetingHost/EmployeeService.svc"
binding="wsHttpBinding" bindingConfiguration="EmployeeService"
contract="EmployeeServiceReference.IEmployeeService" name="EmployeeService">
<identity>
<servicePrincipalName value="host/7TK3T3J.fareast.corp.microsoft.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
Service's config
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBindingWithTXFlow" transactionFlow="true" />
</wsHttpBinding>
</bindings>
<services>
<service name="GreetingHost.EmployeeService" behaviorConfiguration="MyBehaviors">
<endpoint address="http://localhost/GreetingHost/EmployeeService.svc"
binding="wsHttpBinding" bindingConfiguration="wsHttpBindingWithTXFlow"
name="EmployeeService" contract="GreetingHost.IEmployeeService" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
</system.serviceModel>
You may try this -
[IgnoreDataMember]
public virtual Employee Employee { get; set; }
Sorry for the late reply ;)
disable LazyLoading in DbContext.
I know this question is been asked before here but still I'm not sure what to select.
My service will be called from many 3 party system in the enterprise. I'm almost sure the information the service will collect (MyBigClassWithAllInfo) will change during the products lifetime. Is it still a good idea to expose objects?
This is basically what my two alternatives:
[ServiceContract]
public interface ICollectStuffService
{
[OperationContract]
SetDataResponseMsg SetData(SetDataRequestMsg dataRequestMsg);
}
// Alternative 1: Put all data inside a xml file
[DataContract]
public class SetDataRequestMsg
{
[DataMember]
public string Body { get; set; }
[DataMember]
public string OtherPropertiesThatMightBeHandy { get; set; } // ??
}
// Alternative 2: Expose the objects
[DataContract]
public class SetDataRequestMsg
{
[DataMember]
public Header Header { get; set; }
[DataMember]
public MyBigClassWithAllInfo ExposedObject { get; set; }
}
public class SetDataResponseMsg
{
[DataMember]
public ServiceError Error { get; set; }
}
The xml file would look like this:
<?xml version="1.0" encoding="utf-8"?>
<Message>
<Header>
<InfoAboutTheSender>...</InfoAboutTheSender>
</Header>
<StuffToCollectWithAllTheInfo>
<stuff1>...</stuff1>
</StuffToCollectWithAllTheInfo>
</Message>
Any thought on how this service should be implemented?
Thanks Larsi
If the information is going to change during the lifetime but you are under the gun to get something up there I would simply create a message that had a list of variant types that could be sent along with a message type version number.. Your bus can view the version number and route it appropriately. That way customers that are stuck with older versions of the message will not have to change the message interface they are using.