Thursday, September 11, 2014

Kendo: binding to raw HTML

All I wanted was to bind the inner HTML of a DIV to some raw HTML, here is how you do that:
View:
<div data-bind="html: problemList"></div>

ViewModel
var viewModel = new kendo.data.ObservableObject({
    problemList: '<ul><li>Problem 1</li> <li>Problem 2</li></ul>'
});


Friday, July 2, 2010

WCF Method not found only effects SOAP services

I thought I was going to have to blow the OS away on my laptop since it's the only computer I've got that is experiencing this error with SOAP services (REST works great):

The problem:
Method not found: 'Void System.IdentityModel.Selectors.SecurityTokenRequirement.set_IsOptionalToken(Boolean)'.


Stack trace:
at System.ServiceModel.Security.SecurityProtocol.AddSupportingTokenProviders(SupportingTokenParameters supportingTokenParameters, Boolean isOptional, IList`1 providerSpecList)
at System.ServiceModel.Security.SecurityProtocol.OnOpen(TimeSpan timeout)
at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.ClientSecurityChannel`1.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

The solution:
KB976394 - WCF: Make OutgoingSupportingToken public

Reference:

Friday, January 29, 2010

CF HttpWebRequest does not allow writing to the request stream by default

While trying to send data via a request stream, I ran into this error in the compact framework:
ex = {"Either ContentLength must be set to a non-negative number, or SendChunked set to true in order to perform the write operation when AllowWriteStreamBuffering is disabled."}

This was a bit confusing since I didn't get this error when running from a windows client.  I finally figured out that I have to allow writing to the stream:

private void SendData(WebRequest request, object dto)
{
   // I had to add this for the CF framework. It isn't true by default.
   if (request is HttpWebRequest)
      ((HttpWebRequest) request).AllowWriteStreamBuffering = true;

   using (Stream requestStream = request.GetRequestStream())
   {
         if (IsJsonRequest(request))
            SendDataAsJson(requestStream, dto);
        else SendDataAsXml(requestStream, dto);
   }
}

MSUnit toolbar does not work or is grayed out

If you have a library with MSUnit tests in it (probably because you converted MBUnit or NUnit tests to MSUnit tests) and the MSUnit toolbar will not work (stays grayed out), you are probably missing the ProjectTypeGuids. The line your missing from the library project file in the top most PropertyGroup is this one:


<projecttypeguids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</projecttypeguids>

The line above identifies the project as a test project ({3AC096D0-A1C2-E12C-1390-A8335801FDAB}) in the C# ({FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}) language.


Reference that I found after the fact:




Friday, December 4, 2009

JSON Serialization

The Problem:
Here is the error that took me a few days of back-and-forth with an India programming team to figure out:

DateTime values that are greater than DateTime.MaxValue or smaller than DateTime.MinValue when converted to UTC cannot be serialized to JSON.
at System.Runtime.Serialization.Json.JsonWriterDelegator.WriteDateTime(DateTime value)
at System.Runtime.Serialization.XmlWriterDelegator.WriteDateTime(DateTime value, XmlDictionaryString name, XmlDictionaryString ns)


The Solution:
I found that I had an uninitialized date time property (meaning it was equal to DateTime.MinValue) in my data transfer object (DTO). If your WEST of GMT, this doesn't cause a problem; however, if your EAST of GMT, the DataContractJsonSerializer will puke.

Saturday, November 7, 2009

WCF REST HttpStatusCode.Unauthorized status code does not work

Alternate title: WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Unauthorized does not work.
Alternate title: HttpStatusCode.Unauthorized turned into HttpStatusCode.NotFound

The problem:
I spent at least three hours tracking this stupid thing down. The problem that I ran into was Forms Authentication. What's happening is that I am returning HttpStatusCode.Unauthorized (401), but forms authentication is routing the error to the login page. If you don't have a Login.aspx, you will get a resource not found error (HttpStatusCode.NotFound - 404).

If you can change your authentication mode to Windows and the problem goes away, you have this problem.
OR
If you use the browser to hit your REST web service that requires authentication (it returns a 401 status code) and it routes you to your aspx login screen, you have this problem.

Possible solutions:
  • Check out this MSDN article: Supporting HTTP Authentication and Forms Authentication in a Single ASP.NET Web Site . If for some reason this link dies, search for Mixed Authentication Disposition ASP.NET Module (MADAM), which the name of the HttpModule that the MSDN article talks about that allows you to use both HTTP authentication (in this case basic/digest) and Forms authentication in the same web site.
  • I did run across a couple of post were people wanted to use both Windows and Forms authentication together. In those post, it was suggested that the people create a virtual directory in IIS so that you could have two different web.config that specify different authentication methods. I don't know if this will work for this problem, but it is a possible alternative.





Thursday, September 10, 2009

Remote Desktop Drive sharing not working

I ran into a Windows 2003 server on our local network today that would not allow me to share drives so that I could upload/download files to/from the server.

My remote desktop settings look like this:


However, when I connected and opened up windows explorer, my local drives did not appear in the tree view on the left.

Update ->  There two ways to fix this.

Way 1:
After a little bit of digging, I discovered that the group policy for drive sharing (a.k.a. "Drive redirection") was not configured on the Windows 2003 server. This can be fixed by using the MMC snap in called "Group Policy Object Editor":


After navigating to "\Local Computer Policy\Computer Configuration\Administrative Templates\Windows Components\Terminal Services\Client/Server data redirect", I changed the "Do not allow drive redirection" from "Not Configured" to "Disabled" under and it worked fine afterward:




Way 2:
This can also be accomplished this way on Windows Server 2003:



Steps from the Administrative tools window under the control panel.
  1. Double click on "Terminal Service Configuration"
  2. Left click "Connections" on the dialog
  3. Right click "Rdp-Tcp" in the right hand windows.
  4. Uncheck "Drive mapping" on the "Client Settings" tab.